在ASP.Net中的SQL Server DB中编辑记录 [英] Editing record in SQL Server DB in ASP.Net

查看:68
本文介绍了在ASP.Net中的SQL Server DB中编辑记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


填充DataTable之后,我试图在SQL数据库中编辑记录.
代码是

Hi,
After filling DataTable, I am trying to edit my record in SQL Database.
The code is

Dim dRow As DataRow
    dRow = dSet.Tables("tblTest").Rows(0)
    dRow.BeginEdit()
    dRow.Item("Name") = txtName.Text
    dRow.EndEdit()
    dAdt.Update(dSet, "tblTest")


但是它返回错误Object reference not set to an instance of an object.它出现在dRow = dSet.Tables("tblTest").Rows(0)
上 请指教.
感谢


But it returns error, Object reference not set to an instance of an object. It comes on dRow = dSet.Tables("tblTest").Rows(0)
Please advise.
Thanks

推荐答案

很可能您的数据集中没有名为tblTest的表.使用调试器,检查数据集中的表是什么.您可以将dSet.Tables添加到手表中并展开以查看内容.
Most likely you don''t have a table called tblTest in your dataset. Using debugger, check what are the tables in your dataset. You can add dSet.Tables to your watches and expand it to see the contents.


检查dSet.Tables.Count,如果它大于零,请检查dSet.Tables("tblTest").Rows.Count.
Check dSet.Tables.Count, and if it is greater than zero, check dSet.Tables("tblTest").Rows.Count.


在数据集dSet 中没有表tblTest 或表tblTest 中没有任何行.确保存在表和行计数.

OP:传递带有修改的行的DataRow集合时,更新需要有效的UpdateCommand

相反,dAdt.Update(dSet, "tblTest")使用dSet.Tables("tblTest").AcceptChanges().
Either you don''t have a table tblTest in the dataset dSet or you don''t have any row in table tblTest . Make sure the existence of table and row count.

OP: Update requires a valid UpdateCommand when passed DataRow collection with modified rows

Instead dAdt.Update(dSet, "tblTest") use dSet.Tables("tblTest").AcceptChanges().


这篇关于在ASP.Net中的SQL Server DB中编辑记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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