1
Reply

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

Sinoyolo Zatelela

Sinoyolo Zatelela

Jun 27, 2011
4.3k
0

    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.


    nadeem janu
    July 02, 2011
    0