c# mysql count,通过C#的Access数据库查询功能总是返回0 COUNT(*)

Please look into following code:

using (OleDbConnection openCon = new OleDbConnection(ConfigurationManager.AppSettings["AccessConnectioString"]))

{

openCon.Open();

string tc = string.Empty;

string ttc = string.Empty;

if (!string.IsNullOrEmpty(QSetId))

{

tc = "select count(*) as [Count] from ABC where QSetId = @qSetId and TText like 'RT*'";

}

else

{

tc = "select count(*) as [Count] from PQR where TText like 'RT*'";

}

using (OleDbCommand qtc= new OleDbCommand(tc))

{

qtc.Connection = openCon;

if (!string.IsNullOrEmpty(QSetId))

qtc.Parameters.Add("@qSetId", OleDbType.VarChar).Value = QSetId;

OleDbDataReader dr1 = qtc.ExecuteReader();

while (dr1.Read())

{

ttCnt = (int)dr1["Count"];

}

}

openCon.Close();

}

I am always getting count as 0 instead of some integer value. While debugging I take the query and execute in MS ACCESS 2013, it gives me correct result. I am not getting what is the issue.

解决方案

You are getting tripped up by the difference in LIKE wildcard characters between queries run in Access itself and queries run from an external application.

When running a query from within Access itself you need to use the asterisk as the wildcard character: LIKE 'RT*'.

When running a query from an external application (like your C# app) you need to use the percent sign as the wildcard character: LIKE 'RT%'.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值