Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All
I am doing code in C# windows application where the query value I have to get in C#
Below I give the code
SQL
string qry = "Select COUNT(rack)FROM Report ";
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand(qry, conn);
OleDbDataReader dr = cmd.ExecuteReader();


where I check that the SQL query given total number of row is 19
But how can I store that in C#
Thanks To All
Posted
Updated 30-Jul-12 21:16pm
v2

 
Share this answer
 
Hi,
You can use OleDbDataAdapter[^] to get the values and store it to DataTable[^] or DataSet[^]
Try this:
C#
DataTable dt = new DataTable();
string qry = "Select COUNT(rack)FROM Report";
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand(qry, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);//Here you are having a datatable with all your 19 columns


All the best.
--Amit
 
Share this answer
 
C#
SqlCommand cmd=new SqlCommand("Select COUNT(rack)FROM Report");
cmd.Connection=con;
con.Open();
int i=cmd.ExecuteScalar();
con.Close();

The variable i will have the count now.
 
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