C#计数语句 [英] C# count statement

查看:307
本文介绍了C#计数语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写C#代码并使用Access数据库,

如果我使用count语句,我如何使用该语句的结果并给它整数变量。

#换句话说,count语句的结果是5

int x = count语句的结果。

解决方案

在Access中你会发出一个SELECT声明:

  SELECT  COUNT(*) FROM  MyTable 

然后,您可以通过DataReader / DataAdapter像任何其他数据一样在C#代码中检索此值,也可以直接在ExecuteNonQuery语句中检索此值。


查看一个示例 - 在ACCESS数据库中计算数据? [ ^ ]


如果我理解你的问题,你想要执行你的MS-Access数据库查询返回co使用 OleDB 连接到MS-Access数据库。

http://msdn.microsoft.com/en-us/library/5ybdbtte(v = vs.71).aspx



然后使用 ExecuteScalar 获取查询结果。请参阅以下链接。

http:// msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executescalar.aspx

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.

解决方案

In Access you would issue a SELECT Statement:

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.


See one example - Counting data in ACCESS database?[^]


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


这篇关于C#计数语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆