我想插入到一個MySQL表。這裏是我的代碼...如何從asp.net使用vb插入到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列均與足夠的空間(VARCHAR 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表的任何提示將不勝感激!
不要忘記關閉連接(更好地在使用語句中) – Steve