Discuz!NT官方社区

首页 » Web开发 » ASP.net技术讨论 » 数据库.dnt_topics[急][求救]
摆渡 - 2008-5-22 12:23:00
各位大侠:



我从另一个表想要把一些贴子导入到.dnt_topics,dnt_post1表中结果不成功啊
老提示重复:
不能在具有唯一索引 'list' 的对象 'dbo.dnt_topics' 中插入重复键的行。
userid - 2008-6-18 17:21:00
兄弟,我也碰到类似的情况,是因为你没有注意到dnt_topics表中的lastpostid一直都在递增.在向表中新添内容时,先取出dnt_topics表中的lastpostid;将其lastpostid+1再写入数据表中.
方法也给你把:
int lastpostid = 0;
        string selectlastpostid = "select top 1 lastpostid from dnt_topics ORDER BY lastpostid DESC";
        SqlCommand cmd0 = new SqlCommand(selectlastpostid, conn1);
        SqlDataReader dr3 = cmd0.ExecuteReader();
        while (dr3.Read())
        {
            lastpostid = Convert.ToInt32(dr3["lastpostid"]);
        }
        lastpostid = lastpostid + 1;
嘿嘿,自己根据自己的代码修改一下.
1
查看完整版本: 数据库.dnt_topics[急][求救]