我正在制作一个程序,用于管理图书发行并返回我们的初级项目,它已接近完成但有一个问题,我似乎无法插入数据。我用google搜索了但是它们似乎都没有用。我有一个模块和5个表格。这是模块:
Public rs As ADODB.Recordset
Public cn As ADODB.Connection
Public sql As String
Public Category As String
Public Function SetCon()
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\Database.mdb;Persist Security Info=False"
cn.Open
End Function
Public Function SetRs()
Set rs = New ADODB.Recordset
rs.Open sql, cn, adOpenStatic, adLockOptimistic
End Function
Public Function CloseRS()
Set rs = Nothing
'End Function
ublic Function CloseCon()
Set cn = Nothing
End Function
这是我表单的代码:
Private Sub cmdCancel_Click()
Unload Me
frmMain.Show
End Sub
Private Sub cmdDone_Click()
SetCon
sql = "SELECT * FROM tblStudents WHERE StudID='" + txtStudID.text + "'"
SetRs
cn.Execute "INSERT INTO tblStudents(Books Recieved) VALUES('" + txtBooks.text + "')"
MsgBox "SUCCESS!!!", vbInformation, "Success!"
Adodc1.Refresh
txtStudID.text = ""
txtBookID.text = ""
CloseRS
CloseCon
End Sub
Private Sub Form_Load()
Call fillbooks
listBooks.Enabled = False
End Sub
先谢谢^ _ ^