SqlDataAdapter Update()用于将数据表数据更新到db [英] SqlDataAdapter Update() for update datatable data into db
问题描述
HI to all,
我需要从SqlDataAdapter.Update(dttable)触发更新查询。
从SqlDataAdapter.Update(dttable)更新查询后,我的代码不会返回任何异常。
但是数据库表中没有显示任何更改。
这是我的示例代码。
Dim dasave As New SqlDataAdapter(strSelect,con)
dasave.SelectCommand.CommandTimeout = 0
dasave.SelectCommand.Transaction = tran
Dim cb As SqlCommandBuilder
cb = New SqlCommandBuilder(dasave)
Dim iIndex As Integer = dasave.Update(dTable)
注意:con:Connection,tran:事务,dtable的行状态是修改。
代码不返回任何异常,但数据库表没有更新。
请尽早告诉我。?
感谢你。
如果你没有得到任何例外,并且你已经修改了rowstate,那么你会看到你所看到的:< br>基本上AcceptChanges将所有行设置为标记为未修改,然后在运行update时,就适配器而言,没有要更新的行。
请看这里:
; DataAdapter的.Update返回0并且不更新SQL Server中的表。"
http://blogs.msdn.com/spike/archive/2009/03/02/dataadapter-update-returns- 0和 - 没有按叔更新的表式-SQL server.aspx 搜索结果,HTH,点击//迈克尔搜索结果
HI to all ,
I need to fire update query from SqlDataAdapter.Update(dttable) .
My code doesn't return any exception after update query from SqlDataAdapter.Update(dttable).
But there is not any changes shown in database table .
Here is my sample code.
Dim dasave As New SqlDataAdapter(strSelect, con)
dasave.SelectCommand.CommandTimeout = 0
dasave.SelectCommand.Transaction = tran
Dim cb As SqlCommandBuilder
cb = New SqlCommandBuilder(dasave)
Dim iIndex As Integer = dasave.Update(dTable)
Note : con:Connection ,tran:Transaction ,row state of dtable is Modified.
Code doesn't return any exception but database table is not updating.
Please tell me as early as you can .?
Thanking you .
If you don't get any exceptions, and if you have modified the rowstate, AcceptChanges(), then you will see what you are seeing:
Basically AcceptChanges sets all rows to be marked as not modified, and then when you run update, there are no rows to update as far as the adapter is concerned.
Have a look here:
"DataAdapter.Update returns 0 and doesn't update the table in SQL Server."
http://blogs.msdn.com/spike/archive/2009/03/02/dataadapter-update-returns-0-and-doesn-t-update-the-table-in-sql-server.aspx
HTH
//Michael
这篇关于SqlDataAdapter Update()用于将数据表数据更新到db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!