Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public int membercount(string tbl, string condition)
{
  string query = null;
  if (condition.Trim().Length > 0) 
  {
    query = query + "where" + condition;
  }
  else
  {
    query = query;
  }
  cmd = new SqlCommand(query, con);
  dr = cmd.ExecuteScalar();
  return a;
}
´

[edit]Code block added[/edit]
Posted
Updated 6-Jun-13 22:07pm
v3
Comments
Richard MacCutchan 7-Jun-13 3:37am    
This is your third basic question on the same subject. Try checking your code, and using your debugger to find the problem.

1 solution

In the Code.... Even though query is null u are passing to cmd and u are trying to execute query... May be it's the error.. Try assign some value to query if it's Null.. or u can execute cmd in if (condition.Trim().Length > 0) cond'n

Hope this explanation Works...
 
Share this answer
 
v2
Comments
Raja Sekhar S 7-Jun-13 4:15am    
So Did This Solve Your Question...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900