I am trying to pass a list to database (SQL Server 2008 R2) using user defined table types but get some errors my code is:
public int DAL_SaveIncramentSalary(tbl_Employee_Master obj, List < dtIncrementSalary > tbl) {
try {
SqlParameter[] objSqlParameter = new SqlParameter[4];
objSqlParameter[0] = new SqlParameter("@Company_ID", obj.Company_ID);
objSqlParameter[1] = new SqlParameter("@Employee_ID", obj.Employee_ID);
objSqlParameter[2] = new SqlParameter("@Salary_Month", obj.Govt_DA);
objSqlParameter[3] = new SqlParameter("@dt", SqlDbType.Structured);
objSqlParameter[3].Value = tbl;
objSqlParameter[3].Direction = ParameterDirection.Input;
DataSet fdd = SqlHelper.ExecuteDataset(_cnnString2, "usp_Insert_Increment_Salary_List", CommandType.StoredProcedure, bjSqlParameter);
DataSet fddd = SqlHelper.ExecuteDataset(_cnnString2, "usp_Insert_Increment_Salary_List", objSqlParameter);
DataSet ds = SqlHelper.ExecuteDataset(_cnnString2, CommandType.StoredProcedure, "usp_Insert_Increment_Salary_List", objSqlParameter);
return SqlHelper.ExecuteNonQuery(_cnnString2, CommandType.StoredProcedure, "usp_Insert_Increment_Salary_List", objSqlParameter);
} catch (Exception ex) {
throw new Exception(ex.Message);
}
}
I got error like this:
Dataset dff error : Parameter count does not match Parameter Value count. DataSet fddd error : ailed to convert parameter value from a List1 to a IEnumerable
1. DataSet ds error :Failed to convert parameter value from a List1 to a IEnumerable
1.
SQL Server user defined type
CREATE type dtincrementsalary AS TABLE
(
head_id INT NULL,
salamt NUMERIC(18,2) NULL,
per FLOAT NULL,
oldsalamt NUMERIC(18,2) NULL,
oldper FLOAT NULL
) sql PROCALTER
PROCEDURE [DBO].[Usp_insert_increment_salary_list] ( @Company_ID INT,
@Employee_ID INT,
@Salary_Month INT,
@dt DTINCREMENTSALARY readonly )
AS
BEGIN
SELECT *
FROM @dt
END
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…