I am trying to run this code
public long getTopicCountWithTag(String tag)
{
long count;
query = " SELECT count(*) FROM [DB_us2].[dbo].[discns] where tags like '%@tags%'";
try
{
com = new SqlCommand(query, con);
com.Parameters.AddWithValue("@tags", tag);
con.Open();
sdr = com.ExecuteReader();
sdr.Read();
count= sdr.GetInt32(0);
}
catch (Exception e)
{
count = -1;
throw e;
}
finally
{
con.Close();
}
return count;
}
its giving output 0 . So i try figure out what is the problem and run sample query on management studio but output is different its giving 1. After trying all permutation combination, i think problem is with this statement com.Parameters.AddWithValue("@tags", tag); might be possible @tags is not replaced in query.