Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server
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 3-Jan-13 5:15am
Comments
CHill60 at 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 at 3-Jan-13 11:52am
   
i got the solution thank u

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your problem is going to be here:
 
            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.
  Permalink  
Comments
selva_1990 at 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)

  Print Answers RSS
0 OriginalGriff 420
1 CHill60 410
2 Sergey Alexandrovich Kryukov 384
3 PIEBALDconsult 245
4 BillWoodruff 243


Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100