我正在尝试使用 MySQL 5 和 asp.net 4
我成功链接并显示了来自 MySQL 数据库的数据,但问题出在 DML 命令中!!
请看我的代码
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyConnection As String = "server=localhost;User Id=root;password=123;database=cms"
Dim Connection As New MySqlConnection(MyConnection)
Connection.Open()
Dim Sql As String = "INSERT INTO [CMS.tbimages] ( Title,Description) VALUES (parm2,parm3);"
Dim cmd As New MySqlCommand(Sql, Connection)
cmd.Parameters.Add(New MySqlParameter("parm2", "hajjaj"))
cmd.Parameters.Add(New MySqlParameter("parm3", "hajjaj"))
cmd.ExecuteNonQuery()
cmd.Connection.Close()
End Sub
End Class
我所做的是一个用于测试插入命令的简单页面,我添加了一个按钮,当我点击它时它应该执行插入命令!!
但是当我点击它时它给我错误:
#42000 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 '[CMS.tbimages] ( Title,Description) VALUES (parm2,parm3)' at line 1
不是:我尝试了许多其他方法来更改插入语句:
“插入 [tbimages] ( [Title], [Description]) VALUES (?, ?)”
"INSERT INTO [tbimages] ([Title], [Description])
值(?标题,?描述)”
INSERT INTO [tbimages] ( [Title], [Description]) VALUES (Title, Description)
试试这个:
Dim Sql As String = "INSERT INTO CMS.tbimages ( Title,Description) VALUES (?parm2,?parm3);"
Dim cmd As New MySqlCommand(Sql, Connection)
cmd.Parameters.Add(New MySqlParameter("?parm2", "hajjaj"))
cmd.Parameters.Add(New MySqlParameter("?parm3", "hajjaj"))
此外,this教程可能会有所帮助。
我是一名优秀的程序员,十分优秀!