Suppose, we want to process individual user records so we can not write a query again and again and poll to database. It's time taking process.
So, to reduce it, what we will do,
We will fetch all records, Suppose, we have a table called 'employee master' containing huge data in it.
So, we will store in DataTable at once, meaning writing a below query
On the Page Load
Select * from Employee_Master order by emp_name;
ViewState["Employee_data"] = dt_employee;
//here dt_employee is your Datatable object which contains all Employee records.
Now, use Select method,
Suppose we want record of a particular Employee,then
in any events, where you want to populate particular Employee record, write
if(ViewState["Employee_data"]!=null)
{
DataTable dt_emp = Ctype(ViewState["Employee_data"],DataTable);
//Here Ctype is used for casting purpose, you can also use DirectCast instead on
Ctype
If(dt_emp.rows.count>0)
{
//declare DataRow array as
DataRow[] dr_employee = dt_emp.Select("emp_id='"& pass_employee_id &"'");
//Where emp_id is your column name and pass_employee_id is variable in which you will pass particular Employee-Id
Note: Select method returns always Array of DataRow
//Check if dr_employee is null or it's Length is 0 as
if(dr_employee!=null)
{
if(dr_employee.Length>0)
{
//Now, take another DataTable as
DataTable dt_new_employee = null;
dt_new_employee = dr_employee.CopyToDataTable();
//Note: CopyToDataTable will give you datatable.
dtl_view_employee_details.DataSource = dt_new_employee;
dtl_view_employee_details.DataBind();
}
}
}
}
So, here you learn Select method, it's useful for filtering/search criteria.
for this, you do not need to go to Database and fetch single row.