I am using visual studio 2012 and creating a project. I want to use inbuilt sql server with VS 2012. I have create a service based databse i.e. student1.mdf. I have a button and when i click on the button, data should be permanentlly saved onto the database. But its not happening. I have not received any error but data is not saving. I am using this code:-
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(global::proje.Properties.Settings.Default.student1ConnectionString);
try
{
string sql = "insert into smple (name) values('"+textBox1.Text+"')";
SqlCommand cmd = new SqlCommand(sql,con);
con.Open();
cmd.ExecuteNonQuery();
// this.smpleTableAdapter.Fill(this.student1DataSet2.smple);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
finally
{
con.Close();
}
}