重置主键 [英] Reset primary key

查看:152
本文介绍了重置主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到答案做这个在线,但显然它不能做(我的意思是在应用层面,而不是数据库)。我有一个需要完全清除我的数据集,并重新在同一时间的主键。任何想法?

I've tried to find an answer to do this online but apparently it can't be done (I mean at the app level, not database). I have a need to clear out my dataset completely and reset the primary key at the same time. Any ideas?

另外,我们的黑客,我可以用的是重新初始化数据,但是这似乎并不可能,以及因为数据集的应用程序不同类别之间共享(我创建Program.cs中共享数据集)。

Alternatively, one hack i can use is to reinitialize the dataset but that doesn't seem possible as well since the dataset is shared between different classes in the app (I'm creating the shared dataset in Program.cs).

感谢

法鲁克

更新:

好吧,我试过这样:

MyDataSet sharedDS =新MyDataSet();

MyDataSet sharedDS = new MyDataSet();



. . .

CleanDS()

{

    MyDataSet referenceDS = new MyDataSet(); 
    sharedDS.Table1.Reset(); 
    sharedDS.Merge(referenceDS);



}

}

我原来的问题就解决了但现在我得到一个列1 System.ArgumentException不属于表1,我可以看到在数据集查看器中列,也可以看到填充行。另外请注意,我可以手动重新创建整个数据集,我仍然得到同样的错误。任何想法?

My original problem is solved but now I get an System.ArgumentException for Column1 does not belong to Table1 where I can see the columns in the DataSet Viewer as well as see the populated rows. Also note that I can manually re-create the entire DataSet and I still get the same error. Any ideas?

推荐答案

我的autoincrementseed和autoincrementstep尝试过了,它最后的作品。这里是为他人的参考:

i tried it with the autoincrementseed and autoincrementstep and it finally works. here's for the reference of others:

sharedDS.Clear();
sharedDS.Table1.Columns[0].AutoIncrementStep = -1;
sharedDS.Table1.Columns[0].AutoIncrementSeed = -1;
sharedDS.Table1.Columns[0].AutoIncrementStep = 1;
sharedDS.Table1.Columns[0].AutoIncrementSeed = 1;

请参见本主题的推理:
http://www.eggheadcafe.com/community/aspnet/10/25407/autoincrementseed.aspx

please see reasoning in this thread: http://www.eggheadcafe.com/community/aspnet/10/25407/autoincrementseed.aspx

和:
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.autoincrementseed (VS.85)的.aspx

and: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.autoincrementseed(VS.85).aspx

感谢所有您的帮助!

这篇关于重置主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆