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.