如何将datagridview当前行保存到数据库 [英] How to save datagridview current row to database

查看:67
本文介绍了如何将datagridview当前行保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想用一个按钮保存datagridview的数据.但是我应该在保存之前将网格中的行更改为将数据放入数据库中.我想要的是保存当前行的数据而不更改行.

Hi,

I want save the data of the datagridview with a button. But I should change line in the grid before saving to put the data in the database. What I want is save the data of the current line without changing the line.

                   daAdapter = New OleDb.OleDbDataAdapter("Select * from COMPAGNIES order by NOM_COMPAGNIE " & Trie, dbcn)
                   daAdapter.Fill(dtTransac)
                   dvTransac = New DataView(dtTransac)

dgvEdit.DataSource = dvTransac


Public Overrides Function FormSauve() As Boolean
                Dim cmdbuilder As New OleDb.OleDbCommandBuilder(daAdapter)
                daAdapter.Update(dtTransac)
End sub



...
抱歉,我没有正确解释我的问题.当前,如果我在不更改行的情况下更改了网格中的任何数据,则在调用FormSauve子级时,该数据将不会保存在DB中.我应该更改网格中的行并调用FormSauve子项以将数据保存在DB中.

我想要的是能够将数据保存在FormSauve子目录中的数据库中,而无需更改行.

谢谢,



...
Sorry I think I didn’t explain my problem correctly. Currently, if I change any data in the grid without changing lines, the data will not be saved in the DB when I call the FormSauve sub. I should change the line in the grid and call the FormSauve sub to save the data in the DB.

What I want is to be able to save the data in the DB in the FormSauve sub without having to change the line.

Thanks,

推荐答案

,您需要获取单元格的脏数据,并使用它来更新数据.
您也可以使用cellvalidating事件或类似事件来获取e元素的格式化数据,如下所示:

私有子datagridview1_cellvalidating(byval as ......)

在这种情况下,您可以通过以下方式获取数据:

e.formattedvalue

此时您可以获取数据.

然后,您可以将数据检索到其他数据集或将某些数据和更新数据检索到db.


希望对您有用.

问候.
you need to get the dirty data of the cells, and this use to update the data.
also you can use the cellvalidating event or similar to get the formatted data of the e element like this:

private sub datagridview1_cellvalidating(byval e as......)

in this event you can get the data with this:

e.formattedvalue

at this moment you can get the data.

and then, you can retrieve the data to other dataset or something and updata to db.


i hope you this is useful to you.

regards.


您必须在组件处告知您已绑定数据视图以更新绑定.
如果您已使用Infragistics网格,则可以使用grid.activerow.update命令.
you must tell at the component that you have binding the dataview to update the binding.
In case you haved use the Infragistics grid you can use the grid.activerow.update command.


这篇关于如何将datagridview当前行保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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