Friday, November 19, 2010

insert value textbox into mysql database

Programmer Question

I have problems inserting a textboxvalue into a mysql database - there's no errormessage and no inserting. What am I doing wrong



 private void RegisterCustomer()
{
string firstname = txtfirstname.ToString();

OdbcConnection conn;
conn = new OdbcConnection(ConfigurationManager.ConnectionStrings["jConnString"].ConnectionString);
conn.Open();

string sql = "insert into klant (firstname) values (@firstname)";
OdbcCommand cmd = new OdbcCommand(sql, conn);
cmd.Parameters.Add("@firstname", OdbcType.VarChar).Value = firstname;
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Check.Text += ex.ToString() + sql;
}
finally
{
conn.Close();
conn.Dispose();
Check.Text += "OK";
}
}


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails