I'm working first time with local data base of visual studio 2013.
- C# Form Application in visual studio 2013
- Visual Studio 2013 local data base.
"Select" query is working perfect in every situation/condition. But the "insert" query is not inserting the data into the data base and nor showing any king of error. There is not any kind of code error (object decleration ) etc. If i exactly execute the query in SQLQuery tab of visual studio every thing working fine. Here my app.config.
<connectionStrings>
<add name ="connString" connectionString ="Data Source=(LocalDB)\v11.0;AttachDbFilename= |DataDirectory|\KhalidDatabase.mdf ;Integrated Security=True"/>
Here's the code:
try
{
constring = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand("INSERT INTO invoice (customer,date,type,totalBill,printedBy) VALUES ('2','12/12/18','Credit','6000','1');", conDataBase);
conDataBase.Open();
SqlDataReader reader = cmdDataBase.ExecuteReader();
MessageBox.Show("Record Saved Successfully", "SavedSuccessfully");
conDataBase.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
}