As i click update button data is updated but all the data in the table get with it....(same data in whole table)
suggest me what i doing WRONG in it....

private void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection cs = new SqlConnection("Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();
            da.UpdateCommand = new SqlCommand("Update Lib_member_details set member_name=@member_name,member_address=@member_address,member_contact_number=@member_contact_number,member_email_id=@member_email_id,member_password=@member_password,membershiptype_id=@membershiptype_id", cs);
            da.UpdateCommand.Parameters.Add("@member_name", SqlDbType.VarChar).Value = textBox2.Text;
            da.UpdateCommand.Parameters.Add("@member_address", SqlDbType.VarChar).Value = textBox3.Text;
            da.UpdateCommand.Parameters.Add("@member_contact_number", SqlDbType.Int).Value = Convert.ToInt32(textBox4.Text);
            da.UpdateCommand.Parameters.Add("@member_email_id", SqlDbType.VarChar).Value = textBox5.Text;
            da.UpdateCommand.Parameters.Add("@member_password", SqlDbType.Int).Value = Convert.ToInt32(textBox6.Text);
            da.UpdateCommand.Parameters.Add("@membershiptype_id", SqlDbType.Int).Value = Convert.ToInt32(comboBox1.SelectedValue);
            cs.Open();
            MessageBox.Show("member data updated!");
            da.UpdateCommand.ExecuteNonQuery();
            cs.Close();

Without a WHERE clause in your SQL statement the UPDATE function will change data of every record in the table. I would suggest changing the statement to something like:

Update Lib_member_details set member_name=@member_name,member_address=@member_address,member_contact_number=@member_contact_number,member_email_id=@member_email_id,member_password=@member_password,membershiptype_id=@membershiptype_id
WHERE member_id = @member_id

Assuming that your database table has a member_id column and you can pass that parameter to it. Basically you should add all columns of the primary key of the table to ensure that only one record is updated.

This article has been dead for over six months. Start a new discussion instead.