Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
suppose i fire query like..
"select * from customer"
so how can i store it in variables???
Posted
Comments
Guy Van den Nieuwenhof 30-Mar-12 14:27pm    
Can you be more specific? What do you want to store, a customer record into a customer enity. Do you want to use ADO or an ORM

I hope this will help you.

C#
SqlConnection con = new SqlConnection("your connection string");
SqlCommand cmd = new SqlCommand("your select quary", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
if (con.State == ConnectionState.Closed)
    con.Open();
adp.Fill(dt);

if (dt.Rows.Count > 0)
{
   string name=dt.Rows[your row index]["your column name"].toString();
}
 
Share this answer
 
Hi
You can use the following.
datatableforQuery=getdatafromdatabase();
session["Keepdata"]=datatableforQuery;


where getdatafromdatabase() is the mathod that retrive the data from DB query("
SQL
select * from customer"

)

this session variable is very intelligent it will cast to datatable automatically.

another ways is use
a)Viewstate
b)Hashtable
c)temp table in sql server

Hope it will help you.

Thanks
 
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