Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why records is not updating by the code given below ? No any error and exceptions are giving message also shown record updated but when i see in table the records are not updated why ?Please help me.

C#
private void button3_Click(object sender, EventArgs e)
        {
            string sa = textBox1.Text.Trim();
            try
            {
                string connetionString = null;
                connetionString = "Data Source=JDPANDEY-PC;Initial Catalog=amsco;User ID = sa;Password= 123";
                cnn = new SqlConnection(connetionString);

                cnn.Open();

                ds = new DataSet();
                string sql = "select * from employee";
                da = new SqlDataAdapter(sql, cnn);
                da.Fill(ds, "employee");
                int r = 0;
                DataRow[] rs;
                rs = ds.Tables["employee"].Select("eid='" + textBox1.Text.Trim() + "'");
                r = rs.Length;
                if (r > 0)
                {
                    string str = "UPDATE employee set ename='" + textBox2.Text.Trim() + "',fname='" + textBox3.Text.Trim() + "' WHERE  eid ='" + textBox1.Text.Trim() + "'";
                    cmd = new SqlCommand(str, cnn);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Record UPDATED");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cnn.Close();

        }
Posted

1 solution

This code is working fine at my end.After updating the record refresh your database table..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900