请问怎么添加。谢谢!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'模 块 功 能 : 使 用 ADO 对 象 添 加 数 据
'最 后 修 改 时 间 : 6 月 6 日
'修 改 员 : 梁 嘉 辉 (if)
'E - Mail : pruana@126.com
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim g_Connect As ADODB.Connection
Dim g_Recordset As ADODB.Recordset
Private Sub Form_Load()
Set g_Connect = CreateObject("ADODB.Connection")
Dim strConnection As String
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\书刊类别库1.mdb"
g_Connect.Open strConnection
End Sub
Private Sub Command1_Click()
Dim sql As String
If Trim(Text1.Text) = "" Then
MsgBox "类别编号为空", vbokoly + vbExclamation, ""
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "类别名称为空", vbokoly + vbExclamation, ""
Text2.SetFocus
Exit Sub
End If
Set g_Recordset = CreateObject("ADODB.Recordset")
sql = "SELECT * FROM 书刊类别 WHERE 类别编号 ='" & Text1.Text & "'"
g_Recordset.Open sql, g_Connect, adOpenKeyset, adLockPessimistic
If g_Recordset.EOF Then
g_Recordset.AddNew
g_Recordset.Fields("类别编号") = Trim(Text1.Text)
g_Recordset.Fields("类别名称") = Trim(Text2.Text)
g_Recordset.Update
MsgBox "添加成功", vbOKOnly, ""
g_Recordset.Close
Else
MsgBox "类别编号号重复", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
g_Recordset.Close
Exit Sub
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set g_Connect = Nothing
Set g_Recordset = Nothing
End Sub