LIKE query on an Access database via C# always returns COUNT(*) of 0

不问归期 提交于 2019-12-01 11:19:19

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%'.

Try ExecuteScalar() method

Replace This:

 OleDbDataReader dr1 = qtc.ExecuteReader();
 while (dr1.Read())
 {
    ttCnt = (int)dr1["Count"];
 }

With This:

 ttCnt = Convert.ToInt32(qtc.ExecuteScalar());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!