Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void toolStripButton3_Click_1(object sender, EventArgs e)
        {

            int damage = Convert.ToInt16(numericUpDown1.Value);
            UGIcon.Open();
            cmd = new SqlCommand("select * from purchase", UGIcon);
            SqlDataReader s = cmd.ExecuteReader();
            while (s.Read())
            {
                if (toolStripTextBox1.Text != s["cm"].ToString())
                {
                    s.Close();
                    MessageBox.Show("Please check the name");
                }
               
                
            }
            UGIcon.Close();   
            if (textBox2.Text == "")
                {
                    errorProvider1.SetError(textBox2, "Provide Owner name");
                }
                else if (textBox3.Text == "")
                {
                    errorProvider1.SetError(textBox3, "Provide Address");
                }
                else if (numericUpDown2.Value >= damage)
                {
                    MessageBox.Show("check Damage quantity");
                }
                else if ((maskedTextBox1.Text.Trim().Length <= 10))
                {
                    MessageBox.Show("Provide full phone number");
                }
                else
                {
                    UGIcon.Open();
                    cmd = new SqlCommand("update purchase set om='" + textBox2.Text + "', address='" + textBox3.Text + "', phone='" + maskedTextBox1.Text.ToString() + "',baled='" + numericUpDown2.Value + "',paid='" + textBox9.Text + "' where cm='" + toolStripTextBox1.Text + "'", UGIcon);
                    SqlDataReader dr;
                    dr = cmd.ExecuteReader();
                    dr.Close();
                    MessageBox.Show("Details has been updated sucessfully", "Update Window", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    UGIcon.Close();
                }
            }

        }

where is the error need help
Posted
Comments
CHill60 3-Jan-13 11:22am    
Which line is giving you the error - debug this in the IDE and highlight or quote the line that is giving the issue
selva_1990 3-Jan-13 11:52am    
i got the solution thank u

1 solution

Your problem is going to be here:

C#
while (s.Read())
{
    if (toolStripTextBox1.Text != s["cm"].ToString())
    {
        s.Close();
        MessageBox.Show("Please check the name");
    }


}


You're closing the connection inside the loop that is trying to read from the connection.
 
Share this answer
 
Comments
selva_1990 3-Jan-13 11:52am    
thank u bro

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