I
Ivan Sammut
Hi,
I am using a Mysql Database with c# and I am trying to insert a record in
my table. My code is as follows.
MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
//
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType.VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.VarChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbType.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();
But somehow the value I am passing in the paramters is not going and in the
table I am always ending with a record filled with null values.
Any idea?
Ivan
I am using a Mysql Database with c# and I am trying to insert a record in
my table. My code is as follows.
MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
//
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType.VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.VarChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbType.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();
But somehow the value I am passing in the paramters is not going and in the
table I am always ending with a record filled with null values.
Any idea?
Ivan