我对 vb6 完全陌生,我想知道为什么这段代码不起作用。它有运行时 424 错误。我需要做什么?每当我尝试运行它时。我无法访问它说空的数据库。这是整个代码。
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=db_Inventory; User=root;Password=;Option=3;"
End Sub
Private Sub Cmd_Add_Click()
If Txt_Pname.Text = "" And Txt_Pprice.Text = "" Then
MsgBox ("Please enter details")
Else
rst.Open "select * from tbl_product", db, adOpenStatic, adLockOptimistic, adCmdText
rs.AddNew
rs("Prod_Name") = Txt_Pname.Text
rs("Prod_Price") = Txt_Pprice.Text
rs.Update
rs.Close
MsgBox ("Product Added!")
End If
End Sub