none
ERROR [42000] [MySQL] [ODBC 3.51 Driver][mysqld-4.0.15-nt] Parameter SQL with ODBC driver

    Question

  • I have tried to connect to mySQL database through parameter SQL with ODBC 3.51 driver.
    I have received the following error message:
    ERROR [42000] [MySQL] [ODBC 3.51 Driver][mysqld-4.0.15-nt] 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 'field' at line 1 at System.Data.Odbc.OdbcConnection.HandlerError

    My code in VB.NET is as follows:

    Dim myConnectionString as String
    Dim MyConn as OdbcConnection
    Dim MyCmd as New OdbcCommand
    Dim SQL as String

    myConnectionString = "Provider=MSDASQL; DRIVER={MySQL ODBC 3.51 Driver}; Server=localhost; UID=user; PWD=password; database=db; Option=16387"


    MyConn = New OdbcConnection(myConnectionString)

    SQL = "SELECT Field1 FROM Table1 WHERE Field1 = ?field1Name"

    MyCmd.Parameters.AddWithValue("?field1Name", Textbox1.text)

    MyCmd.Comandtext = SQL.ToString

    MyConn.Open()
    MyCmd.Connection = MyConn

    GridView1.DataSource = MyCmd.ExecuteReader

    GridView1.DataBind()

    MyConn.Close()


    Can you help me please with this issue?

    Thank you very much

    Saturday, August 18, 2007 5:48 PM

Answers

All replies

  •  

    Use the MySql .Net connector instead of ODBC

     

    http://dev.mysql.com/downloads/connector/net/5.0.html

    Saturday, August 18, 2007 8:53 PM
  • Hello Ken,

     

    thank you very much for your answer.

     

    I have downloaded the MySQL.Net connector.

    How can i use it in the Visual Studiu.NET?

    What shall i do that the methods from the MySql.NET connector will be visible for me in the Visual Studio.NET?

    How should i change then the connection string?

     

    Thank you very much for your help.

     

    With best regards

    L.S.1.

    Monday, August 20, 2007 8:11 PM
  • Hi L.S.1.,

     

    I think you need to add a reference to these components. For more information, check the document provide by MySQL team.

            http://dev.mysql.com/doc/refman/5.0/en/connector-net.html

    Samples

           http://dev.mysql.com/doc/refman/5.0/en/connector-net-examples-mysqlconnection.html

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Hope this helps.

    Best regards.

    Wednesday, August 22, 2007 9:54 AM