1.11M Members

how to retrieve data and display in textbox in c#

 
0
 

Hiiiii!!

Can any one help me, how to retrieve information of employee in text boxes if i enter employee number in c# using data adapter and also why we use data adapter?


plzzzzzzz....

Thanking You!!!

 
0
 

I assume you have already figured this out on your own ?

 
0
 

You may use ExecuteScalar();

example:
SqlCommand cmd = new SqlCommand("select Count(*) as Total from Customers",connect);

textBox1.Text = cmd.ExecuteScalar().ToString();

That all.

 
1
 

Try this and see... U'll Get the result...
:)

try{
                con.Open();
                cmd = new SqlCommand("Select Employee_Name,Designation,Salary,Department,DateOfJoining,DateOfBirth,Qualification from EmployeeDetails where Employee_Id=@aa", con);
                cmd.Parameters.Add("@aa", SqlDbType.Int).Value = textBox1.Text;
                dr = cmd.ExecuteReader();
                if (dr.HasRows == false)
                {
                    throw new Exception();   
                }
                if (dr.Read())
                {
                    // textBox1.Text = dr[0].ToString(); Since U r going to give the ID and retrieve in textBox1.
                    textBox2.Text = dr[0].ToString();
                    textBox3.Text = dr[1].ToString();
                    textBox4.Text = dr[2].ToString();
                    textBox7.Text = dr[3].ToString();
                    dateTimePicker1.Text = dr[4].ToString();
                    dateTimePicker2.Text = dr[5].ToString();
                    textBox5.Text = dr[6].ToString();
                }
            }
            catch
            {
                Result.Text = "THE GIVEN ID IS UNAVAILABLE";
            }
            finally
            {
                con.Close();
            }
 
-1
 

ThankX Buddy it works,,,,
but how to use it in Text Changed event of textbox......
????
will really appreciate if u get it???
bye...

 
1
 

bsr990.

I'm glad you got it helpful. If you want to ask question, start your own thread.

Thread Closed.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article