Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello


hope you all are doing well !


i have two tables
- book
contain book id
and
- ss
contain book id and Snumber

I want the user to get the form from the book id when he insert the Snumber in textBox1

this is the code

private void button1_Click(object sender, EventArgs e)
        {
            


            String constring = "Data Source=V-PC;Initial Catalog=SMA;Integrated Security=True";
            SqlConnection con1 = new SqlConnection(constring);
           

            String Search = "Select bookID from ss where Snumber='" + this.textBox1.Text + "'";
           
            SqlCommand SearchS = new SqlCommand(Search, con1);
            SqlDataReader myreader;
            

            try
            {
                con1.Open();
                myreader = (SearchS.ExecuteReader());
                


                if (Search =="1")
                {
                    this.Hide();
                    S1 d1 = new S1();
                    d1.ShowDialog();
                }
                else if (Search == "2")
                {
                       this.Hide();
                   S2 e3 = new S2();
                    e3.ShowDialog();
                }
                /*else if   ( Search == "3")
                {
                       this.Hide();
                   S3 e3 = new S3();
                    e3.ShowDialog();
                }*/

                

                while (myreader.Read())
                {
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            con1.Close();
        }
        }



there is no error
but in debugging when I press the button that contain this code

the button do nothing !!



Did I do something wrong or forget something ?
Posted
Comments
[no name] 28-Jun-13 11:35am    
What does "the button do nothing" mean? The click event does not run? It runs but does not do what you expect? What is it that you expect? What does it actually do?
09lolo 28-Jun-13 11:50am    
the button should take me to another form when he insert his Snumber.
[no name] 28-Jun-13 11:48am    
Your If statements are completely wrong. Search is never going to be equal to "1", "2" or "3" because you have set Search to be your SELECT statement and there is nothing in your code that changes that.
09lolo 28-Jun-13 11:52am    
I know I did something wrong that's why I came here : )
I am just a beginner.

Thank you for your time.
[no name] 28-Jun-13 11:55am    
And I am just telling you what you did so you can fix it and learn from your experience.

Well, I'm not really surprised! Lets just take "irrelevant" code away:
C#
private void button1_Click(object sender, EventArgs e)
        {
...
            String Search = "Select bookID from ss where Snumber='" + this.textBox1.Text + "'";
...           
                if (Search =="1")
                {
...
                }
                else if (Search == "2")
                {
...
                }
...
        }
Since Search will never equal either value it does nothing with it.

Probably what you want to do is to use the values in the myreader returned data to make those decisions...
 
Share this answer
 
C#
int x /*define it global*/
while (myreader.read())
{
    x = int.parse(myreader[0].ToString());
}
if (x =="1")
                {
                    this.Hide();
                    S1 d1 = new S1();
                    d1.ShowDialog();
                }

I have given you a solution as much I have understood your question
hope this will help you


[edit]Code block fixed, spelling[/edit]
 
Share this answer
 
v2

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

  Print Answers RSS


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