Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hi guy i have a problem that i try every way to make Posting search results to textbox but always return nothing this is my code
  private void btnNamesearch_Click(object sender, EventArgs e)
        {
 
           bool temp = false;
            SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Educational System;Data Source=DREAMS");
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT EmpName, ExcutionOrder FROM Employee WHERE EmpName  ='" + txtusernameSearch.Text.Trim() + "'", con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                txtemployee.Text = dr["EmpName"].ToString();
                txtExcutionOrder.Text = dr["ExcutionOrder"].ToString();
 
                temp = true;
            }
            if (temp == false)
                MessageBox.Show("not found");
 
            con.Close();
            dr.Close();
 
        }

its work and when i make breakpoints it gets date but nothing display
and i have another problem that i have got 4 com boxes which fill in form load
suppose when i make search it should display the value of selected from search and this will make problem because it loads with form load ?? plz help really i think more but still need experiences through windows form thanks a lot
Posted 25-Dec-12 10:48am
ost3z640
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

while (dr.Read())
            {
if(dr.HasRows)
{
     txtemployee.Text = dr["EmpName"].ToString();
     txtExcutionOrder.Text = dr["ExcutionOrder"].ToString();
 
}
else
{
        MessageBox.Show("not found");
}
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

thanks a lot the problem was in another code in the from where it conflict with this code but i need to know to fill combobox from select order by searched item
  Permalink  
Comments
ProgramFOX at 26-Dec-12 4:23am
   
If you've a comment to an answer, click on the "Have a Question or Comment?" button, but please don't post a comment as an answer.
ost3z at 26-Dec-12 11:36am
   
OK this my first time to participate thanks a lot

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 480
1 Gihan Liyanage 225
2 OriginalGriff 174
3 Bhavik_Patel 170
4 PhilLenoir 155
0 Sergey Alexandrovich Kryukov 8,653
1 OriginalGriff 7,132
2 CPallini 2,598
3 Richard MacCutchan 2,060
4 Abhinav S 1,808


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 26 Dec 2012
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