I'm getting this error:
System.ArgumentException HResult=0x80070057 Message=No mapping exists from object type System.Collections.Generic.List`1[[System.Data.SqlClient.SqlParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type. Source=<Cannot evaluate the exception source>
I've googled, and the examples are where someone tries to use an object instead of the text value for the SqlParameter
value. Like, they try to use someControl
instead of someControl.Text
. In my case, below, toStatus
and fromStatus
are already strings. I'm not sure what else could be the problem. What am I missing?
public void UpdateStatus(SearchCriteria searchCriteria, string fromStatus, string toStatus)
{
var sql = new StringBuilder();
var sqlParameters = new List<SqlParameter>();
sql.Append("UPDATE Schema.Table SET Status = @toStatus WHERE Status = @fromStatus");
sqlParameters.Add(new SqlParameter("@toStatus", toStatus) { SqlDbType = SqlDbType.VarChar });
sqlParameters.Add(new SqlParameter("@fromStatus", fromStatus) { SqlDbType = SqlDbType.VarChar });
db.ExecuteSqlCommand(sql.ToString(), sqlParameters);
}
ExecuteSqlCommand
expects an array instead of a List
.
Use as below
db.ExecuteSqlCommand(sql.ToString(), sqlParameters.ToArray());
User contributions licensed under CC BY-SA 3.0