更新DataTable中的Sql Identity [英] Update Sql Identity in DataTable

查看:67
本文介绍了更新DataTable中的Sql Identity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在使用以下代码在Sql数据库中使用SqlDataAdapter(sAdapter)更新DataTable(dTable):

Dear All,

I am updating DataTable (dTable) using SqlDataAdapter (sAdapter) in Sql Database with following code:

using (SqlCommandBuilder sBuilder = new SqlCommandBuilder(sAdapter))
{
      sAdapter.UpdateBatchSize = 0;
      sAdapter.Update(dTable);
}
//Working Excellent


我想在dTable中更新Sql Identity.我该怎么办?

注意:行数可以是1到10.

问候!
Aman


I want to Update Sql Identity in dTable''s particular. How can I do this?

Note: Rows can be one to ten.

Regards!
Aman

推荐答案

您可以将列的AutoIncrement字段设置为true.

由于无法在表中更新标识列,因此我不明白为什么需要在此处进行此操作.
You can set the AutoIncrement field of the column to true.

Since an identity column cannot be updated in a table, I dont see why you would need to do this here.


如果问题是您不知道标识的值插入的行中的几件事:
If the problem is that you don''t know the value of the identity of the inserted row, few things:

  • in the next statements you can use SCOPE_IDENTITY()[^] to retrieve the lastly added value of an identity column (in any table)
  • you can also define OUTPUT[^] clause to an insert statement which can return data from the newly inserted row. This data can be retrieved for example in adapters RowUpdated event.


大家好,

这是答案:
使用DataSet和DataAdapter插入关系数据 [
Hi Guys,

Here is answer:
Inserting relational data using DataSet and DataAdapter[^]

I just added the RowUpdated event in my code.

Regards!
Aman


这篇关于更新DataTable中的Sql Identity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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