I am trying to insert customer details into a database. Following is the code which is throwing an ArgumentException
- how can I handle it?
try
{
string constring = "DataSource=.\\SQLEXPRESS;"+"Integrated security=true;"+"User Instance=true;"+"AttachDBFileName=|DataDirectory|Database1.sdf;"+"Initial catalog=Database1";
using(SqlConnection connection = new SqlConnection(constring))
{
connection.Open();
SqlCommand cins = new SqlCommand("INSERT INTO Customer(cid,cname,mobi)" + "VALUES(@cid , @cname , @mobi)", connection);
cins.Parameters.AddWithValue("@cid", textBox3.Text);
cins.Parameters.AddWithValue("@cname", ncustname.Text);
cins.Parameters.AddWithValue("@mobi", ncustmno.Text);
cins.ExecuteNonQuery();
MessageBox.Show("new customer added");
ncustpn.Hide();
Class1.refreshcustomertable(cdgv);
cdgv.Show();
}
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}