1,105,214 Community Members

how to retrieve data and display in textbox in c#

Member Avatar
ghanathe
Newbie Poster
1 post since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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!!!

Member Avatar
JerryShaw
Posting Pro in Training
467 posts since Nov 2006
Reputation Points: 46 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
fzy
Newbie Poster
1 post since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

You may use ExecuteScalar();

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

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

That all.

Member Avatar
Karthika_g
Newbie Poster
12 posts since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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();
            }
Member Avatar
bsr990
Newbie Poster
1 post since Feb 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

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

Member Avatar
__avd
Posting Genius (adatapost)
6,703 posts since Oct 2008
Reputation Points: 1,811 [?]
Q&As Helped to Solve: 1,272 [?]
Skill Endorsements: 61 [?]
Moderator
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article