I hope that someonw can help me with this. This code is inteneded to add a new column to a mariaDB based on data extracted from a filename. I get the error " near @sname = s111206 syntax error. The variable @sname contains the proper data for the test file. I am new to working with databases so forgive me my ignorance. The info that was passed to me by this forum on a previous question was right on and I am working with connector.net and Visual Basic Express 2010 with good results for the most part.

I have tried several variation of the sql but have not had any luck, and have not been able to find an answer in the connector.net help. Thanks for your consideration.

Jules
(julesjenson@me.com)

        'create column for filename date as sxxxxxx
        Try
            conn.Open()
            Dim sql As String
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            sql = ("ALTER  TABLE attendance ADD @sname varchar(14)")
            command.CommandText = sql
            command.Connection = conn
            adapter.SelectCommand = command
            command.Prepare()
            command.Parameters.AddWithValue("@sname", sname)
            command.ExecuteNonQuery()

        Catch ex As MySql.Data.MySqlClient.MySqlException
            MessageBox.Show(ex.Message)
        End Try
        conn.Close()

Answer Answered by wlad in this comment.

I think you're doing AddWithValue too late (after prepare). There is a forum that is more specific for MySQL with .NET http://forums.mysql.com/list.php?38

Comments

Comments loading...