How to fix this issue in my code:
str = "SELECT " + columnName + " FROM [tableA] where Company_ID=" + HaksId.ToString() + "";
cmd.CommandText = str;
cmd.Connection = conn;
adpt.SelectCommand = cmd;
adpt.Fill(ds);
In the above code there is only required things mentioned obviously conn is connection string I have mentioned all things they are working fine there is some other error in this code
Where columnname is string and Id is integer
Error is
Conversion failed when converting the nvarchar value '[Select]' to data type int.
Return value is value of type decimal(18,0)
Hoping for your suggestion
Thanks
EDITED
columname="Avg"
HaksId=1
Company_ID is of nvarchar
Result of query should be 2.
SOLUTION
This help me out,
"SELECT " + columnName + " FROM [tableA] where Company_ID='" + HaksId+ "'"
columnNameorHaksId; so: what is the resulting value ofstrhere? Also: Doesds.Tables[0]have columns defined? If so: as what?