I'm trying to pass the list of my class as DbParameter. Probably the table type is defined in my stored procedure.
Now, I'm not getting how to pass the List<> into the stored procedure as there is table type defined which accepts Tables only.
Here, I'm putting my method.
public static AddCustomer(List<Customer> customer)
{
List<DbParameter> lstDbParameters = null;
try
{
#region Set the Parameters
lstDbParameters = new List<DbParameter>();
SqlParameter dbAcceptedBillDetails = new SqlParameter("@Customers",
customer);
dbAcceptedBillDetails.SqlDbType = SqlDbType.Structured;
lstDbParameters.Add(dbAcceptedBillDetails as DbParameter);
lstDbParameters.Add(CDDAC.MakeDbParameter(dbProvider,
"@ErrorMessage",
DbType.String,
null,
500,
ParameterDirection.Output));
#endregion
//Call the static ExecuteNonQuery method.
CDDAC.ExecuteNonQuery(dbProvider,
connectionString,
"AddCustomer",
CommandType.StoredProcedure,
lstDbParameters.ToArray());
}
catch (Exception ex)
{
throw;
}
}
And I'm getting error like this:
Failed to convert parameter value from a List
1 to a IEnumerable1.
I know i can convert this list into DataTable and then pass it in the stored procedure but it seems time consuming. :(
CDDAC.MakeDbParameterand the stack trace of the error.DataTable,IDataReaderor aIEnumerable<SqlDataRecord>- you need to provide one of those three options - take your pick