提示添加成功,FormMain.DataGrid2中有记录显示,但在sql server 中却没有见到添加的记录.那那些记录是保存在哪里的呢?难道DATAGRID有保存记录的功能?
Option Explicit
Dim cn As ADODB.Connection
Dim res As ADODB.Recordset
Private Sub cmdClose_Click()
FormMain.Adodc1.Refresh
Unload Me
End Sub
Private Sub Command1_Click()
Dim i
Set cn = New ADODB.Connection
Set res = New ADODB.Recordset
cn.open "Provider=SQLOLEDB;User ID=sa;PWD=;Initial Catalog=;Data Source=."
res.CursorLocation = adUseClient
res.open "select * from 次表", cn, adOpenStatic, adLockOptimistic
Set FormMain.DataGrid2.DataSource = res
res.AddNew
On Error Resume Next
res.Fields("ID") = ID.Text
res.Fields("物品编号") = no.Text
res.Fields("名称") = mingcheng.Text
res.Fields("数量") = suliang.Text
res.Fields("单价") = danjia.Text
res.Fields("小计") = xiaoji.Text
res.Fields("登记日期") = dtpRigDate.Value
res.Update
FormMain.Adodc1.Refresh
Set res = Nothing
MsgBox "添加记录成功", vbOKOnly, "提示"
If Option1.Value = False Then
Unload Me
End If
End Sub