List:MySQL and .NET« Previous MessageNext Message »
From:Reggie Burnett Date:September 16 2004 5:14pm
Subject:RE: Bug with parameters?
View as plain text  
Someone didn't read the release announcement very closely.  ;-)
The syntax for setting parameters has changed.  Now you use ? instead of
@ to mark parameters.  This change was necessary for proper
compatibility with MySQL.  However, realzing that people may have lots
of code to change, I have included a connection string option that will
enable the old syntax.  Add "old syntax=yes" to  your connection string
and it will work.  However, you should read the help on MySqlCommand.
There is a note included that talks about the tradeoffs of doing this.

-reggie

-----Original Message-----
From: David Anderson [mailto:david@stripped] 
Sent: Thursday, September 16, 2004 12:08 PM
To: DotNet List
Subject: Bug with parameters?

I have the following bit of code which crashes with error "Column 'id' 
cannot be null" when run with the new connector, but the same thing 
works with the ByteFX . Is this a bug, or am I not calling parameters 
correctly?

Regards
David

using System;
using MySql.Data.MySqlClient;

namespace mytest1
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
           
            // Set up a mysql connection using MySql-AB
            string connstr = "Persist Security 
Info=False;database=pnet;server=benden;user
id=dbuser;Password=p1nestap";
            MySqlConnection conn = new MySqlConnection(connstr);
            MySqlCommand cmd = new MySqlCommand();
            conn.ConnectionString = connstr;
            conn.Open();
            string cmdstr = "insert into rawreviews (id, review) 
values(@id, @review)";
            cmd.Connection = conn;
            cmd.CommandText = cmdstr;
            cmd.Parameters.Add("id", 4);
            cmd.Parameters.Add("review", "Fourth Review");
            cmd.ExecuteNonQuery();
            conn.Close();
        }
    }
}



-- 
MySQL on .NET Mailing List
For list archives: http://lists.mysql.com/dotnet
To unsubscribe:    http://lists.mysql.com/dotnet?unsub=1


Thread
Bug with parameters?David Anderson16 Sep
  • RE: Bug with parameters?Reggie Burnett16 Sep