更新DatagridView记录(Updating DatagridView Records)

   IT问题网   2020-06-27 00:00:00

问 题

我做错了什么?我似乎可以理解这个错误"对象引用没有设置为对象的实例。"请帮助我,谢谢!



 da2 =  oledbdataadapter("  select * from purchasedb2",condb)
da2.fill(ds2," purchasedb2"
对于 i = 0 podg.rows.count- 1
ds2.tables(" purchasedb2")。rows(inc).item(" itemno")= podg.rows.item(i).cells( 0 )。value.tostring
ds2.tables(" purchasedb2")。rows(inc).item(" description")= podg.rows .item(i).cells( 1 )。value.tostring
ds2.tables("" purchasedb2")。rows(inc).item(" 数量")= podg.rows.item(i).cells( 2 )。value.tostring
ds2.tables(" purchasedb2")。rows(inc).item(" unitprice")= podg.rows.item(i).cells( 3 )。值.tostring
ds2.tables(" purchasedb2")。rows(inc).item( " 金额")= podg.rows.item(i).cells( 4 )。value.tostring
dim cb2 as <跨班="code-keyword">新 oledbcommandbuilder(da2)
da2.update(ds2," purchasedb2"
下一步

解决方案

你说这是错误的代码行:

 ds2.tables("  purchasedb2")。rows(inc).item("  itemno")= podg.rows.item(i).cells( 0 )。value.tostring 




因此,您需要确定哪个部分未设置为实例,或者换句话说,哪个部分为空或什么都没有。您可以通过设置断点并运行代码来完成此操作。然后使用quickwatch。 (突出显示要查看的部分,右键单击,选择快速观察)。首先确保ds2存在。然后确保其中有一个名为purchasedb2的表。然后确保该表中有行。等等



我注意到你试图设置 row(inc),但我不是看看 inc 是什么/哪里。你的意思是在这里使用变量吗?或者,您设置它的datagridview对象可能没有任何行,而且它是 .cells(0)部分未设置为对象?



此外,您可能需要考虑使用 for each 来遍历表格或网格。你似乎正在迭代datagridview,在这种情况下你可以使用这样的东西:

 对于 每个 dgvr  as  datagridview row   podg.rows 
' 现在,当您想引用datagridviewrow时,您可以使用dgvr.item(0).value而不是podg.rows(i).cells(0).value

next


或循环遍历表:

 对于 每个 myrow  as  datarow  in  dtmydatatable.rows 
" 使用myrow而不是dtmydatatable.rows(i)的代码.item(0)

下一步




使用它比设置这些计数变量更容易一些。希望这有帮助。

这里是代码的场景,我将在datagridview中输入数据,然后如果我点击保存,它将保存在数据库中,添加现在正常工作。我的问题是,在数据库中搜索记录,例如我搜索了记录的"描述",所以我在datagridview中添加到数据库中的所有记录都应该"仍然"存在于datagridview中。但是这没有发生,它只会输出数据库中的第一条记录,如果我想在datagridview中出现多行怎么办?

你访问数据库的方法是什么? / blockquote>

标签:更新记录



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何从tortoiseSVN获取最新版本,然后使用CruiseControl.NET在msbuild中构建它(how to get latest version from tortoiseSVN and then build it in msbuild with CruiseControl.NET)

problem hi, i had a one asp.net solution in ...

请再帮忙,善良的人(Please help again, kind people)

problem hi all, so frustrated. i did two days'' researc ...

如何使用c#,net动态地在textarea中添加文本?(how to add text in textarea dynamically using c#,net)

problem string query = string.empty; query = "select mess ...

在Visual Studio 2010中创建Crystal Reports(Creating Crystal Reports in Visual Studio 2010)

problem im creating crystal reports using visual studio 2 ...

控制以填充数据并执行回发(control to fill the data and perform postback)

problem hi, is there any control to fill the data from da ...

System()vs CreateProcess()vs ShellExecute()(System() vs CreateProcess() vs ShellExecute())

problem here''s one for everyone, i''m running a batch fi ...

将TCL代码转换为C ++ ...(Convert a TCL code to C++...)

problem for {set i 128} {$ilt;256} {incr i 1} { eval lut ...

如何从二进制文件中读取浮点值(How Read Float value from Binary File)

problem hi. i do want to read float value from binary fi ...

使用.bak文件还原数据库(Restore Database using.bak file)

problem good evening everybody, please say how to restor ...

在gridview中显示总和(Show sum In gridview)

problem my gridview has data which looks like below (for ...

Ajax客户端脚本错误(Ajax Client side script error)

problem if (typeof(sys) === #39;undefined#39; ...

如何在UP和DOWN键进行编码(How to code at the UP and DOWN key)

problem i want to move picture box up and down when a use ...

如何计算excel 2003中的时间平均值(how to calculate time averge in excel 2003)

problem hii to all. if any body knows how to calculateave ...

控制相关问题(Control related issue)

problem respected sir, i have a page in which i m gettin ...

在运行时动态绘制div(draw div dynamically at runtime)

problem hiii all, i have a page which i draw all its attr ...

转换数据库值(Convert a databse value)

problem i have a table one field is price and ...

如何使单元格的内容可见为false(How do i make the content of a cell visible false)

problem how do i make the content of a cell visible false ...

qtwebkit并连接cpp和javascript(qtwebkit and connect cpp and javascript)

problem hi to all i am using qwebkit i have a cpp object ...

response.flush&amp;到Response.End(problem with response.flush &amp; response.end)

problem hello everybody, i have used response.flush() wi ...

ShellExecute()不执行(ShellExecute() Not Executing)

problem i''m running a batch file from c++ code.when i ru ...