datagrid 的问题
我用datagrid与表绑定,然后通过双击datagrid的列来调用一个FORM窗体,上面显示datagrid的数据.想通过FOME修改datagrid数据,但保存老出错误!请高手指点. 这是保存按扭的代码
Private Sub Command1_Click()
Dim sql As String
sqltxt = "select * from jgz"
Set brs = exesql(sqltxt)
brs.Fields("员工编号") = Trim(Text2.Text)
brs.Fields("员工姓名") = Text1.Text
brs.Fields("部门") = Text3.Text
brs.Fields("产品编号") = Text4.Text
brs.Fields("产品名称") = Text5.Text
brs.Fields("工序编号") = Text6.Text
brs.Fields("工序名称") = Text7.Text
brs.Fields("合格数") = Text8.Text
brs.Fields("单价") = Text9.Text
brs.Fields("合计金额") = Text10.Text
brs.Fields("日期") = DTPicker1.Value
brs.Update
MsgBox "保存成功!", vbOKOnly, "提示"
Text2.Text = ""
Text8.Text = ""
Text1.Text = ""
Text3.Text = ""
Text2.SetFocus
Text10.Text = ""
End Sub
Public Function exesql(ByVal sql As String) As ADODB.Recordset
sql = Trim$(sql)
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\d.mdb"
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = conn
rst.CursorType = adOpenDynamic
rst.LockType = adLockPessimistic
rst.Open sql
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function