getting error in LINQ query

Posted by Rickeybglr under WCF on 1/15/2013 | Points: 10 | Views : 1014 | Status : [Member] | Replies : 0
Here is my function which takes 2 parameter tablename and column name. i need to find out max max of column value

public int getMaxtableId(string colName,string tbName)
{
try
{
using (var dbContext = new LNTF_PMSEntities())
{
string sql = string.Format("select ([{0}]) AS [{0}] FROM [{1}]", colName, tbName);
int max =dbContext.CreateQuery<int>(sql).SingleOrDefault();
return max; }
}
catch (FaultException)
{
return 0;
}

its throwing error.




Responses

(No response found.)

Login to post response