MOHSEN BENAISSA

MOHSEN BENAISSA

  • NA
  • 23
  • 5.5k

use Textbox to display datatable

Oct 16 2018 5:04 AM
Hi friend's
how can i use textbox(primary key in my datatable) whene i write a number all the other informations can display in the windows form
exp :
if i put number "1" in textbox---> code client
the other textbox display (Name, adress, tel....)
 
 
this is my database
 

Answers (1)

1
Suraj Kumar

Suraj Kumar

  • 0
  • 9.9k
  • 2.2m
Oct 16 2018 5:09 AM
Hello,
try this, some modification needed. Write this code on Text Changed event of textbox.
  1. try{  
  2.                 con.Open();  
  3.                 cmd = new SqlCommand("Select Employee_Name,Designation,Salary,Department,DateOfJoining,DateOfBirth,Qualification from EmployeeDetails where Employee_Id=@aa", con);  
  4.                 cmd.Parameters.Add("@aa", SqlDbType.Int).Value = textBox1.Text;  
  5.                 dr = cmd.ExecuteReader();  
  6.                 if (dr.HasRows == false)  
  7.                 {  
  8.                     throw new Exception();     
  9.                 }  
  10.                 if (dr.Read())  
  11.                 {  
  12.                     // textBox1.Text = dr[0].ToString(); Since U r going to give the ID and retrieve in textBox1.  
  13.                     textBox2.Text = dr[0].ToString();  
  14.                     textBox3.Text = dr[1].ToString();  
  15.                     textBox4.Text = dr[2].ToString();  
  16.                     textBox7.Text = dr[3].ToString();  
  17.                     dateTimePicker1.Text = dr[4].ToString();  
  18.                     dateTimePicker2.Text = dr[5].ToString();  
  19.                     textBox5.Text = dr[6].ToString();  
  20.                 }  
  21.             }  
  22.             catch  
  23.             {  
  24.                 Result.Text = "THE GIVEN ID IS UNAVAILABLE";  
  25.             }  
  26.             finally  
  27.             {  
  28.                 con.Close();  
  29.             }