一个按钮,一个DataGrid代码如下:Dim CN As New ADODB.Connection
Dim Rs As New ADODB.RecordsetPrivate Sub Form_Load()
Dim strPath As String
strPath = App.Path & "\ZBGL.MDB"
DataGrid1.AllowAddNew = True
DataGrid1.AllowDelete = True
DataGrid1.AllowUpdate = True
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Persist Security Info=False"
CN.OpenRs.CursorLocation = adUseClient
Rs.Open "select * from zonghe", CN, adOpenDynamic, adLockBatchOptimisticSet DataGrid1.DataSource = RsEnd SubPrivate Sub Command1_Click()
Rs.Update
DataGrid1.Refresh
End Sub按下按钮后没有任何错误提示,表格的指针移到当前所在行,可是就是不能更新到数据库,请高手指点.
Dim Rs As New ADODB.RecordsetPrivate Sub Form_Load()
Dim strPath As String
strPath = App.Path & "\ZBGL.MDB"
DataGrid1.AllowAddNew = True
DataGrid1.AllowDelete = True
DataGrid1.AllowUpdate = True
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Persist Security Info=False"
CN.OpenRs.CursorLocation = adUseClient
Rs.Open "select * from zonghe", CN, adOpenDynamic, adLockBatchOptimisticSet DataGrid1.DataSource = RsEnd SubPrivate Sub Command1_Click()
Rs.Update
DataGrid1.Refresh
End Sub按下按钮后没有任何错误提示,表格的指针移到当前所在行,可是就是不能更新到数据库,请高手指点.
中的adLockBatchOptimistic是指樂觀性批次更新.
你把Rs.Update改成Rs.UpdateBatch
Private Sub Command1_Click()
rs("字段名")=值
Rs.Update
DataGrid1.Refresh
End Sub
如果是选取datagrid中修改完的数据
Private Sub Command1_Click()
rs("字段名")=datagrid.(列值).value 行值自动返回
Rs.Update
DataGrid1.Refresh
End Sub
Rs.Update
Rs.UpdateBatch
Rs.Update就可更新