Private Sub Command1_Click()
Dim cnn As New Connection
Dim rs As New Recordset
Dim mrc As New Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\data\win.mdb;Persist Security Info=False" '如果不用这个模块也行可以,这一句便是常用的引擎。
cnn.Open
rs.Open "select * from memoA", cnn, adOpenStatic, adLockOptimistic
'AdoRs2.MoveLast
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or DTPicker1.Value = "" Or Text7.Text = "" Or Text8.Text = "" Then
MsgBox "请输入完整数据", vbInformation, "输入不完整"
Else
mrc.Open "select * from memoA where 序号 = " & Trim(Text8.Text) & "", cnn, adOpenStatic, adLockOptimistic '检验输入用户名是否存在
If mrc.RecordCount <> 0 Then
MsgBox "已有相同的序列号", vbInformation, "提示-重新输入序号"
Else
rs.AddNew
rs.Fields(0) = Text8.Text
rs.Fields(1) = Text1.Text
rs.Fields(2) = Text2.Text
rs.Fields(3) = Text3.Text
rs.Fields(4) = Text4.Text
rs.Fields(5) = DTPicker1.Value
rs.Fields(6) = Text7.Text
rs.Fields(7) = Text7.Text
MsgBox "添加成功!", , "提示"
rs.Update
rs.Close
DataGrid1.Refresh
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
'Set rs = cnn.Execute("insert into memoA values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & DTPicker1.Value & "','" & DTPicker1.Value & "','" & Text7.Text & "')")
'MsgBox "添加成功"
End If
End If
cnn.Close
End Sub