这是我的代码和字符串值包含传递的数据,“temp”包含存储在字符串数组中的数据的no。然后将数据存储在sqlparameter
对象中,然后作为SqlQuery
中的对象传递:
public List<T> updateSiteDetails<T>(int SiteId, int CategoryId, string[] values)
{
int temp = values.Count()+1;
int Counter = 0;
SqlParameter[] sParams = new SqlParameter[temp]; // Parameter count
sParams[0] = new SqlParameter();
sParams[0].SqlDbType = SqlDbType.Int;
sParams[0].ParameterName = "@SiteId";
sParams[0].Value = SiteId;
sParams[1] = new SqlParameter();
sParams[1].SqlDbType = SqlDbType.Int;
sParams[1].ParameterName = "@CategoryId";
sParams[1].Value = CategoryId;
for (int i = 2,j=1; i < temp;i++,j++)
{
sParams[i] = new SqlParameter();
sParams[i].SqlDbType = SqlDbType.NVarChar;
sParams[i].ParameterName = "@value"+j;
sParams[i].Value = values[j];
}
object[] parameters=new object[]{sParams};
List<T> SiteDetails = null;
using (SBDEntities db = new SBDEntities())
{
SiteDetails = db.Database.SqlQuery<T>("Sp_Update_AppData", parameters).ToList();//error is here
return SiteDetails;
}
}