1
Reply

How to code a button save, so to save to the database?

    firstly you add the namspace....
    using System.Data.SqlClient;


    private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "Data Source=SR; Initial catalog=nadeem;  user id=sa; password=<123>";
                con.Open();
                SqlCommand cmd = new SqlCommand("insert into login values ('" + textBox1.Text + "',' " + textBox2.Text + " ')", con);
                SqlDataReader dr = cmd.ExecuteReader();
                MessageBox.Show("save your data");
                con.Close();
            }


    Regards-Nadeem.