如何编辑datagridview中的单元格,然后在数据库中更新它 [英] how to edit cells in datagridview and then update it in database
问题描述
我有1个表名数据。
在我的程序中,数据插入工作正常。我也在datagridview中显示数据库详细信息。这也工作正常。
但是当我的datagridview显示插入值的详细信息时,我想编辑/更新单元格中的更改然后我想在数据库中更新它。
假设我有列名称地址phone_no
raju bb 98657900
sss cc 88920000
现在,如果我点击datagridview中的任何一个单元格并进行更改,那么该单元格应该在数据库中更新。
我该怎么办?
i是datagridview概念的新手。
有人可以帮我吗?
i have 1 table name data.
in my program, data insertion is working fine. i am showing the database details in datagridview also.this also working fine.
but when my datagridview is showing the details of the values inserted ,there i want to edit/update changes in cell and then that i want to update it in database.
suppose i have columns as name address phone_no
raju bb 98657900
sss cc 88920000
now if i click on any one of the cell in datagridview and make changes then that cell should be updated in database.
how do i do it?
i am new in datagridview concept.
can anyone help me?
推荐答案
如果你想更新单元格的值更改,那么你需要处理< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx> [MSDN] DataGridView.CellValu eChanged事件 [ ^ ]。在那种情况下,更新你的数据库表。
如果字符串格式正确,你提到的关于从字符串转换为Double的错误应该不会发生。
参考 - [MSDN] Convert.ToDouble方法(字符串) [ ^ ] 。有例子。因此,请确保您提供正确的dtring进行转换。
If you want to update on cell's value change, then you need to handle the [MSDN] DataGridView.CellValueChanged Event[^]. In that event, update your Database tables.
And the Error you mentioned about Conversion to Double from String should not ideally happen if the string is in correct format.
Refer - [MSDN] Convert.ToDouble Method (String)[^]. There are examples. So, make sure you are providing the correct dtring to convert.
您可以查看这些..
http://stackoverflow.com/questions/16530686/vb-net-insert-datagridview-contents-into-database [ ^ ]
http://stackoverflow.com/questions/15629088 / edit-update-datagridview-vb-net-no-database [ ^ ]
http://www.dreamincode.net/forums/topic/68848-how-to-add-delet e-and-update-database-using-datagridview / [ ^ ]
http://www.daniweb.com/software -development / vbnet / threads / 377185 / how-can-i-edit-a-cell-in-datagridview-then-save-the-data-in-my-database [ ^ ]
http://adonetaccess2003.blogspot.com/2011/11/datagridview-add-edit-delete-into.html [ ^ ]
You can view these..
http://stackoverflow.com/questions/16530686/vb-net-insert-datagridview-contents-into-database[^]
http://stackoverflow.com/questions/15629088/edit-update-datagridview-vb-net-no-database[^]
http://www.dreamincode.net/forums/topic/68848-how-to-add-delete-and-update-database-using-datagridview/[^]
http://www.daniweb.com/software-development/vbnet/threads/377185/how-can-i-edit-a-cell-in-datagridview-then-save-the-data-in-my-database[^]
http://adonetaccess2003.blogspot.com/2011/11/datagridview-add-edit-delete-into.html[^]
这篇关于如何编辑datagridview中的单元格,然后在数据库中更新它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!