HI
有人可以告诉我在这段代码中我做错了什么
Protected Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Insert.Click
Dim mydb As New OleDbConnection
mydb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|database.mdb;Persist Security Info=True")
mydb.Open()
Dim sqlstring = "INSERT INTO [maintable] ([field1], [field2]) VALUES (@textbox1, @textbox2);"
Dim mydbcommand As New OleDbCommand(sqlstring, mydb)
TextBox1.Text = mydbcommand.Parameters.Add("@textbox1", OleDbType.VarChar).Value
TextBox2.Text = mydbcommand.Parameters.Add("@textbox2", OleDbType.VarChar).Value
mydbcommand.ExecuteNonQuery()
mydb.Close()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
答案 0 :(得分:5)
我认为你应该使用
mydbcommand.Parameters.Add("@textbox1", OleDbType.VarChar).Value = TextBox1.Text
mydbcommand.Parameters.Add("@textbox2", OleDbType.VarChar).Value = TextBox2.Text
而不是
TextBox1.Text = mydbcommand.Parameters.Add("@textbox1", OleDbType.VarChar).Value
TextBox2.Text = mydbcommand.Parameters.Add("@textbox2", OleDbType.VarChar).Value
尝试并告诉我你是否仍然面临问题