I don't know how to solve this problem.
I want to create simple project in visual studio 08 in C# windows application which can save update delete data from database.
here are the steps i use :
open new project
right click on solution explorer -add- add new items-service-based-database when i select this option it will create new database with dataset.
now the problem is how can i save the data in this database. I tried this code but it shows save data in run time when i stop and run the program data i entered not save in the database.
code :
try
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\DB\\emp.mdf;Integrated Security=True;User Instance=True";
cn.Open();
SqlCommand cmd = new SqlCommand("insert into emp(id,nm,city,dept)values(@id,@nm,@city,@dept)", cn);
cmd.Parameters.AddWithValue("@id", textBox1.Text);
cmd.Parameters.AddWithValue("@nm", textBox2.Text);
cmd.Parameters.AddWithValue("@city", textBox3.Text);
cmd.Parameters.AddWithValue("@dept", textBox4.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Update successful");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
how can i save the data in database.
I hope u can understand the problem.