Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i want to retrieve information from my table based on the value inserted in the ID text-box and populate the rest text-box with their appropriate value. how do i go about that.
Posted
Comments
VJ Reddy 6-Jun-12 11:22am    
Thank you for accepting the solution :)

you need the learn the concepts of ADO.net. Start from here:

Using ADO.NET for beginners[^]

hope it helps :)
 
Share this answer
 
Comments
VJ Reddy 11-Apr-12 11:53am    
Good link. +5
Uday P.Singh 11-Apr-12 11:55am    
thanks VJ :)
bbirajdar 11-Apr-12 12:35pm    
my 5
Uday P.Singh 11-Apr-12 13:15pm    
thanks B Birajdar :)
The article link given by Uday P.Singh is good for learning about ADO.NET.
Now, if you have already populated the DataTables of your DataSet, then to retrieve a DataRow corresponding to the ID entered in a TextBox the following code can be used.
C#
//Assuming Employees is the DataTable, EmployeeID, Name and Address as columns of this table
//If the EmployeeID is the primary key in the table, the Find method
//of DataRowCollection returned by Rows property of DataTable can be used
DataRow row = Employees.Rows.Find(TextBoxID.Text);
if (row != null){
    TextBoxName.Text = (string)row["Name"];
    TextBoxAddress.Text = (string)row["Address"];
}
//If the EmployeeID is not the primary key in the table, then Select method
//of DataTable can be used, which returns an array of DataRows matching
//the filter expression given as the first parameter.
DataRow[] rows = Employees.Select(string.Format("EmployeeID='{0}'",
                    TextBoxID.Text),"",DataViewRowState.CurrentRows);
if (rows.Length > 0){
    TextBoxName.Text = (string)rows[0]["Name"];
    TextBoxAddress.Text = (string)rows[0]["Address"];
}
 
Share this answer
 
v2
Comments
ProEnggSoft 11-Apr-12 12:41pm    
Nicely explained. +5
VJ Reddy 11-Apr-12 12:47pm    
Thank you.
Uday P.Singh 11-Apr-12 13:15pm    
5! good answer
VJ Reddy 11-Apr-12 13:18pm    
Thank you, Uday.
Dear..

USE SQLDATAREADER to retrive data....
 
Share this answer
 

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



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