Here is the code of my add data function
protected void addData(string name,string email,string field,string address,string notes,int phone,string site)
{
DateTime dt = DateTime.Today;
SqlConnection con = new SqlConnection(@"Data Source=GAURAV-PC\SQLEXPRESS;AttachDbFilename=|DataDirectory|\JAMS.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand Cmd = con.CreateCommand();
SqlTransaction trans = con.BeginTransaction();
Cmd.Connection = con;
Cmd.Transaction = trans;
try
{
Cmd.CommandText = "Insert into JAMS_Companies(company,email,website,phone,address,field,notes) values(@name,@email,@site,@phone,@address,@field,@notes)";
Cmd.Parameters.AddWithValue("@name", name);
Cmd.Parameters.AddWithValue("@email", email);
Cmd.Parameters.AddWithValue("@site", site);
Cmd.Parameters.AddWithValue("@phone", phone);
Cmd.Parameters.AddWithValue("@address", address);
Cmd.Parameters.AddWithValue("@field", field);
Cmd.Parameters.AddWithValue("@notes", notes);
Cmd.ExecuteNonQuery();
trans.Commit();
this.Close();
}
catch (Exception e)
{
Console.Write("Haha" + e.ToString());
trans.Rollback();
}
finally
{
con.Close();
}
}
This adds the data temporarily i.e when I rerun the program It shows data in grid but when I check database then there is no data.Kindly Help