我正在尝试插入 mysql 表。这是我的代码...
Dim cmdText = "INSERT INTO complete_log ('cust_id', 'business', 'note', 'date_stamp') values (@cid,@bus,@notey,@datey)"
Dim conn As New MySqlConnection("server=theipofserver;user id=id;password=mypass;database=thedatabase")
Using cmd = New MySqlCommand(cmdText, conn)
conn.Open()
Dim testy As String
testy = TextBox1.Text
Dim dater = Date.Today + TimeOfDay
cmd.Parameters.AddWithValue("@cid", c_id)
cmd.Parameters.AddWithValue("@bus", c_business)
cmd.Parameters.AddWithValue("@notey", testy)
cmd.Parameters.AddWithValue("@datey", dater)
cmd.ExecuteNonQuery()
End Using
但是,我收到以下错误:
MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''cust_id', 'business', 'note', 'date_stamp') values ('ID','null','first one'' at line 1
我要插入的表有 4 列,它们都是具有足够空间的 varchars (varchar(100))
以下是有关错误的更多详细信息...错误发生在第 31 行...
Line 29: cmd.Parameters.AddWithValue("@notey", testy)
Line 30: cmd.Parameters.AddWithValue("@datey", dater)
Line 31: cmd.ExecuteNonQuery()
Line 32: End Using
Line 33: TextBox1.Font.Bold = True
那么,我在这里做错了什么?任何有关插入 mysql 表的更好方法的提示将不胜感激!