Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i write C# code and use Access database,
if i use count statement ,how can i use the result of that statement and give it integer variable.
#in other words the result of count statement was 5
int x= result of count statement.
Posted

In Access you would issue a SELECT Statement:
SQL
SELECT COUNT(*) FROM MyTable
You can then retrieve this value in your C# code either via a DataReader / DataAdapter like any other data or directly as the result of an ExecuteNonQuery statement.
 
Share this answer
 
Comments
Matt T Heffron 2-Jul-13 14:53pm    
Is there a LINQ adapter for Access?
OriginalGriff 2-Jul-13 14:58pm    
Try here:
http://www.codeproject.com/Articles/23599/LinqToSQL-Comprehensive-Support-for-SQLite-Microso
 
Share this answer
 
If I understood your problem right, you want to execute your MS-Access DB query which returns count in your C# code.

Connect to your MS-Access database using OleDB.
http://msdn.microsoft.com/en-us/library/5ybdbtte(v=vs.71).aspx

Then fetch result of your query using ExecuteScalar. Refer below link.
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executescalar.aspx
 
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