Please look into following code:
using (OleDbConnection openCon = new OleDbConnection(ConfigurationManager.AppSettings[\"AccessConnectioString\"]))
{
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());