请查看以下代码:
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();
}
我总是将计数视为 0 而不是某个整数值。在调试时,我在 MS ACCESS 2013 中执行查询并执行,它给了我正确的结果。我不明白是什么问题。