如何更新datagridview [英] How to Update datagridview
本文介绍了如何更新datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Gents,
每次我编辑数据库中的详细信息(例如(删除,添加)),当我查看访问数据库但不更新数据网格视图中的数据时它会完美运行,除非我关闭程序并重新打开它。有没有办法可以刷新datagridview,以便自动更新自己。我使用microsoft access 2007作为我的数据库。
以下是我到目前为止的代码:
Gents,
Each time I edit the details in my database such as (delete, add) it works perfectly when I view the access database but does not update the data in my datagridview except I close the program and re-open it. Is there a way I can refresh the datagridview so that it updates itself automatically. I use microsoft access 2007 as my database.
Below is the code I have so far:
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
If InspDataGridView.SelectedRows.Count <> 0 And lblInsSheet2Edit.Text = "QuarryMech" Then
Dim James As String
James = MsgBox("Confirm this inspection has been completed", MsgBoxStyle.YesNo, "EwekoroII Inspections Tracker")
If James = vbYes And lblWhoLogged.Text = lblInsSheet2Edit.Text Then
Dim agreement As OleDb.OleDbConnection
Dim dldb, myguy As String
myguy = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Methods Inspections.mdb")
agreement = New OleDb.OleDbConnection(myguy)
agreement.Open()
dldb = "UPDATE QuarryMech SET Status = '" & "Done" & "' WHERE Ins_Date = '" & lblReturnedDate.Text & "' AND Inspection = '" & lblReturnedInspection.Text & "'"
Dim halt = New OleDb.OleDbCommand
Try
halt = New OleDbCommand(dldb, agreement)
halt.ExecuteNonQuery()
InspDataGridView.RefreshEdit()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
End Try
End If
推荐答案
你好,
更新datagridview的最佳方法正在使用DataSet。您可以使用向导创建数据集。该向导为数据库的每个表创建TableAdapters。
之后,您可以更轻松地更新数据库。
示例:
Hello,
The best way to update the datagridview is using DataSets. You can create a dataset with the wizard. The wizard create TableAdapters for each table of the database.
After that, you can update the datarid easier.
Example:
MyDataSetTableAdapters.MyTableTableAdapter ta = new MyDataSetTableAdapters.MyTableTableAdapter();
ta.Fill(myDataSet.MyTable);
使用此方法,您可以随时从数据库中获取最后的结果你需要。
我建议你带一位受访者参加微软ado.net的文件。
http://msdn.microsoft.com/en-us/library/e80y5yhx.aspx [ ^ ]
这篇关于如何更新datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文