I have a database that contains a Customer table with the following columns : CustID, CustName, ICNumber, ContactNumber and Address. It is a service-based database.
string localdb = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(localdb);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Customer(CustID,CustName,ICNumber,ContactNumber,Address)values(@CustID,@CustName,@ICNumber,@ContactNumber,@Address)", con);
cmd.Parameters.AddWithValue("@CustID", txtCustID.Text);
cmd.Parameters.AddWithValue("@CustName", txtCustName.Text);
cmd.Parameters.AddWithValue("@ICNumber", txtICNum.Text);
cmd.Parameters.AddWithValue("@ContactNumber", txtContact.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.ExecuteNonQuery();
con.Close();
The code compiles and runs. The problem I am having is that the record is not added into the table after cmd.ExecuteNonQuery(); is called.
Why is the record not showing up in the database table?