datagridview UPDATE -ERROR [英] datagridview UPDATE -ERROR
本文介绍了datagridview UPDATE -ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我的DGV数据库更新时间此错误显示..
无法将类型为''System.Data.DataTable''的对象转换为''System.Windows.Forms.BindingSource''。
我在这里使用代码来更新FUNCION
Hi All
my DGV database UPDATE Time This Error Show..
Unable to cast object of type ''System.Data.DataTable'' to type ''System.Windows.Forms.BindingSource''.
Here I am USING CODE FOR UPDATE FUNCION
Me.Validate()
Dim bindingSource1 As New BindingSource
Dim DTable As New DataTable()
Me.bindingSource1 = Me.dgvView.DataSource
DTable = Me.bindingSource1.DataSource
Me.DaAp.Update(DTable)
MessageBox.Show("UPDATED SUCESSFULLY")
DTable.AcceptChanges()
请告诉我如何使用DGV进行数据库更新
Please Tell Me How Can i Do to database UPDATE using DGV
推荐答案
你真的需要阅读一本VB.NET书。这段代码是没意义的意大利面条。
你没有创建一个新的绑定源来进行数据库更新。最重要的是,你正在创建一个新的空DataTable,然后忽略它并让它超出范围。
您通常在DataTable中拥有数据object,将Grid绑定到它,当用户想要提交更改时,可以调用配置为执行更新的DataAdapter的Update方法。这不是你的代码的替代品,但它归结为:
You REALLY need to go through a VB.NET book. This code is meaningless spaghetti.
You don''t creat a new bindingsource to do a database update. On top of that, you''re creating a new empty DataTable, then ignoring it and letting it go out of scope.
You normally have your data in a DataTable object, bind the Grid to it, and when the user wants to submit changes, you call the Update method of a DataAdapter configured to do the update. This is not a replacement for your code, but it comes down to this:
MyDgv.EndEdit()
MyDataAdapter.Update(myDataTable)
MessageBox.Show("UPDATED SUCESSFULLY")
你发布的其余代码是毫无意义的垃圾。
The rest of that code you posted is meaningless garbage.
这篇关于datagridview UPDATE -ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文