0

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();
            }
        }
2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by Suzie999
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.