in my c# code the request payload is:
{"lstContractInvoicePerdays":[{"ContractInvoicePerDayID":"1061","LastModifiedDate":"2023-04-24T04:37:44"},{"ContractInvoicePerDayID":"1135","LastModifiedDate":"2023-04-24T04:37:45"}]}
Let me help to pass the params in stored procedure as existing logic is not helping
try
{
int? BaseStateProvinceID = null;
List lstContractInvoicePerdays = new List();
lstContractInvoicePerdays = staffCIPDApprovedViewModel.lstContractInvoicePerdays.ToList();
if (lstContractInvoicePerdays.Count == 1)
{
}
CIPDPushReqMod timeCardPushRequest = new CIPDPushReqMod();
List ContractInvoicePerDayIDs = staffCIPDApprovedViewModel.lstContractInvoicePerdays.Select(x=> x.ContractInvoicePerDayIDs.Split(',').Select(int.Parse).ToList();
using (SqlConnection connection = new SqlConnection(db.Database.Connection.ConnectionString))
{
try
{
using (SqlCommand command = new SqlCommand("spGetCIPDForPushToLawson", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@ContractInvoicePerDayIDs", SqlDbType.NVarChar).Value = ContractInvoicePerDayIDs as object ?? DBNull.Value;
if (connection.State != ConnectionState.Closed)
{
connection.Close();
}
connection.Open();
using (var reader = command.ExecuteReader())
{
timeCardPushRequest.TimeCardLst = ((IObjectContextAdapter)db).ObjectContext.Translate(reader).ToList();
reader.NextResult();
timeCardPushRequest.AdditionalComponents = ((IObjectContextAdapter)db).ObjectContext.Translate(reader).ToList();
}
}
}
catch (Exception)
{
}
Tuhin PaulPosted May 1, 2023, 6:02 PM
As per your C# code and stored procedure, it seems that you are trying to pass a list of ContractInvoicePerDayIDs as a parameter to the stored procedure. To achieve this, you need to convert the list of ContractInvoicePerDayIDs into a comma-separated string and then pass it as a parameter to the stored procedure.
Here is the code :
I removed the BaseStateProvinceID variable since it is not being used, and simplified the ContractInvoicePerDayIDs parameter by removing the unnecessary Split and Select(int.Parse) calls.
Basit NisarPosted Apr 29, 2023, 4:09 PM
The procedure is :