Search code examples
c#mysqlado.netmysql-connector

Only MySqlParameter objects may be stored (C#)


I researched this problem but didn't get tangible solution. For your information, I use our general library class for connection and never encountered such a problem. And also I want to say that project runs successfully on my local PC but not on server.

This is the code fragment which I get an error:

    queue_tablename = tablename;

    conn = myconn;
    writecomm = conn.CreateCommand();
    writecomm.CommandText = "insert into "+tablename+" (id,mtype,channel,dt,fromnumber,tonumber,smstext)" +
        "values (?id,?mtype,?channel,?dt,?fromnumber,?tonumber,?smstext)";
    writecomm.Parameters.Add(new MySqlParameter("id", MySqlDbType.Int64));
    writecomm.Parameters.Add(new MySqlParameter("mtype", MySqlDbType.VarChar));
    writecomm.Parameters.Add(new MySqlParameter("channel", MySqlDbType.VarChar));
    writecomm.Parameters.Add(new MySqlParameter("dt", MySqlDbType.DateTime));
    writecomm.Parameters.Add(new MySqlParameter("fromnumber", MySqlDbType.VarChar));
    writecomm.Parameters.Add(new MySqlParameter("tonumber", MySqlDbType.VarChar));
    writecomm.Parameters.Add(new MySqlParameter("smstext", MySqlDbType.VarChar));

This line throws the exception:

writecomm.Parameters.Add(new MySqlParameter("id", MySqlDbType.Int64));

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

Additional information: Only MySqlParameter objects may be stored


Solution

  • I solved the problem and hope it will help who tried above solution tips but can not solve.

    The exception occurred because my connection library uses MySql.Data.dll version 6.2.2.2 but I added a reference of 6.9.9.0. Change your MySql.Data reference, it will help you.

    In my case, my company has another connection library which works with 6.9.9.0 version. That's why, I used the new one and everything is okay.