Hi,
I'm a new here and would like some help with my code please!!
I'm using VS.Net 2003 and connect to MySQL 5.1. The problem I have is passing a value from a Control 'TB_Vorname' to a Command.Parameter 'f_name'. The server keeps recieving NULL instead of the value. Cann anybody let me know where my code in going wrong.
Thanks
Wayne
//Connection to MySQL server
OdbcConnection cn = new OdbcConnection(MyConString);
//Create Odbc command object
OdbcCommand cmd = new OdbcCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@f_name", OdbcType.VarChar, 75).Value = TB_Vorname.Text;
cmd.Parameters.Add("@l_name", OdbcType.VarChar, 75).Value = TB_Nachname.Text;
//Set the Select statement in the CommandText property and set the
//connection property to the "cn" Connection object.
cmd.CommandText = "Insert into name (date_added, date_modified, f_name, l_name)values (now(), now(), @f_name, @l_name)";
cmd.Connection = cn;
try
{
cn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
I'm a new here and would like some help with my code please!!
I'm using VS.Net 2003 and connect to MySQL 5.1. The problem I have is passing a value from a Control 'TB_Vorname' to a Command.Parameter 'f_name'. The server keeps recieving NULL instead of the value. Cann anybody let me know where my code in going wrong.
Thanks
Wayne
//Connection to MySQL server
OdbcConnection cn = new OdbcConnection(MyConString);
//Create Odbc command object
OdbcCommand cmd = new OdbcCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@f_name", OdbcType.VarChar, 75).Value = TB_Vorname.Text;
cmd.Parameters.Add("@l_name", OdbcType.VarChar, 75).Value = TB_Nachname.Text;
//Set the Select statement in the CommandText property and set the
//connection property to the "cn" Connection object.
cmd.CommandText = "Insert into name (date_added, date_modified, f_name, l_name)values (now(), now(), @f_name, @l_name)";
cmd.Connection = cn;
try
{
cn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
Comment