我试图基于数据表行创建多个线程,如果表中有10行,它将创建10个线程。我不断收到此错误“值不能为空。参数名称:值”。我在这里想念什么?
我在第一个catch语句“内部例外”注释的Savedata方法内部出现错误。
try
{
DataProvider DPrvdr = new DataProvider();
DPrvdr.ConnectionString = strConMAS500; // read only
//getting all the sales order
DataTable dt = DPrvdr.GetDataSetSProc("uspMAS500SOSER_GetSO").Tables[0];
List<DataTable> lstDt = SplitTable(dt, MaxSOinThread); // Split the Data table as per MaxSO in Threads - Currently it is 1
if (lstDt != null)
{
Parallel.ForEach(lstDt, (currentdt) =>
{
hashSOTbl = Savedata(currentdt);
});
}
}
catch (Exception ex)
{
LogMessage("Error " + ex.Message);
}
protected Hashtable Savedata(DataTable dt)
{
SOEntityBOLWS_Client c = new SOEntityBOLWS_Client();
Hashtable hashSODetails = new Hashtable();
for (int i = 0; i < dt.Rows.Count; i++)
{
try
{
//initializing the SO object
SOEntityForClient.SalesOrder s = c.GetNewSO(dt.Rows[i]["CreatedBy"].ToString(), dt.Rows[i]["SessionID"].ToString());
string SONO = string.Empty;
s.CustID = dt.Rows[i]["CustID"].ToString().Trim();
s.CompanyID = dt.Rows[i]["CompanyID"].ToString().Trim();
s.CustPONo = dt.Rows[i]["CustPONo"].ToString();
s.CustClassID = (dt.Rows[i]["CustClassID"].ToString());
s.SalesSourceID = (dt.Rows[i]["SalesSourceID"].ToString());
s.CreateUserID = (dt.Rows[i]["CreatedBy"].ToString());
int rowkey = Convert.ToInt32(dt.Rows[i]["RowKey"].ToString());
DataProvider DPrvdrheaderComment = new DataProvider();
DPrvdrheaderComment.ConnectionString = strConMAS500; // read only
SqlParameter[] sqlHeaderComment = new SqlParameter[2];
sqlHeaderComment[0] = new SqlParameter("@DocOwnerKey", rowkey);
sqlHeaderComment[1] = new SqlParameter("@ParentDocType", 801);//801 for header comment
//getting Comment
DataTable dtHeaderComment = DPrvdrheaderComment.GetDataSetParams("uspMAS500SOSER_GetSOComments", sqlHeaderComment).Tables[0];
if (dtHeaderComment.Rows.Count > 0)
{
s.Comments = new List<SOEntityForClient.Comment>();
for (int m = 0; m < dtHeaderComment.Rows.Count; m++)
{
SOEntityForClient.Comment cm = new SOEntityForClient.Comment();
cm.CommentText = dtHeaderComment.Rows[m]["CommentText"].ToString();
cm.ExtCmntID = dtHeaderComment.Rows[m]["ExtCommentID"].ToString();
cm.ParentDocType = 801;
cm.SeqNo = m + 1;
s.Comments.Add(cm);
}
}
DataProvider DPrvdrLine = new DataProvider();
DPrvdrLine.ConnectionString = strConMAS500; // read only
SqlParameter[] sqlline = new SqlParameter[1];
sqlline[0] = new SqlParameter("@RowKey", rowkey);
DataTable dtLine = DPrvdrLine.GetDataSetParams("uspMAS500SOSER_GetSOLine", sqlline).Tables[0];
for (int k = 0; k < dtLine.Rows.Count; k++)
{
SOEntityForClient.SOLine l = new SOEntityForClient.SOLine();
l.ItemID = dtLine.Rows[k]["ItemID"].ToString();
//l.Description = dtLine.Rows[k]["Description"].ToString();
l.QtyOrd = Convert.ToDecimal(dtLine.Rows[k]["QtyOrd"].ToString());
l.UnitMeasID = dtLine.Rows[k]["UnitMeasID"].ToString();
l.UnitPrice = Convert.ToDecimal(dtLine.Rows[k]["UnitPrice"].ToString());
l.TradeDiscPct = Convert.ToDecimal(dtLine.Rows[k]["TradeDiscPct"].ToString());
l.WhseID = dtLine.Rows[k]["WarehouseID"].ToString();
l.PromiseDate = DateTime.Parse(dt.Rows[i]["DfltPromDate"].ToString());
l.RequestDate = DateTime.Parse(dt.Rows[i]["DfltRequestDate"].ToString());
l.ShipDate = DateTime.Parse(dt.Rows[i]["DfltShipDate"].ToString());
DPrvdrLineComment = new DataProvider();
DPrvdrLineComment.ConnectionString = strConMAS500; // read only
SqlParameter[] sqlComment = new SqlParameter[2];
sqlComment[0] = new SqlParameter("@DocOwnerKey", (dtLine.Rows[k]["SOLineKey"].ToString()));
sqlComment[1] = new SqlParameter("@ParentDocType", 802);//802 for line comment
//getting Comment
DataTable dtLineComment = DPrvdrLineComment.GetDataSetParams("uspMAS500SOSER_GetSOComments", sqlComment).Tables[0];
if (dtLineComment.Rows.Count > 0)
{
l.SOLineComments = new List<SOEntityForClient.Comment>();
for (int m = 0; m < dtLineComment.Rows.Count; m++)
{
SOEntityForClient.Comment cm = new SOEntityForClient.Comment();
cm.CommentText = dtLineComment.Rows[m]["CommentText"].ToString();
cm.ExtCmntID = dtLineComment.Rows[m]["ExtCommentID"].ToString();
cm.ParentDocType = 802;//802 for line comment
cm.SeqNo = m + 1;
l.SOLineComments.Add(cm);
}
}
//Save SO line.
s.LineItems.Add(l);
}
try
{
//checking line count
if (s.LineItems.Count != 0)
{
int UpdateProcessStatus = 0;
try
{
string warning = c.SaveSO((dt.Rows[i]["CreatedBy"].ToString()), (dt.Rows[i]["CompanyID"].ToString().Trim()), dt.Rows[i]["TranNo"].ToString(), "801", s, dt.Rows[i]["SessionID"].ToString(), "OverrideDate:true");
if (warning.Contains("Saved"))
{
hashSODetails.Add(dt.Rows[i]["TranNo"].ToString(), dt.Rows[i]["CompanyID"].ToString());
UpdateProcessStatus = 1;
}
else
{
UpdateProcessStatus = 0;
}
DPrvdr = new DataProvider();
DPrvdr.ConnectionString = strConMAS500;
SqlParameter[] sqlParam = new SqlParameter[4];
sqlParam[0] = new SqlParameter("@Tranno", dt.Rows[i]["TranNo"].ToString());
sqlParam[1] = new SqlParameter("@Message", warning);
sqlParam[2] = new SqlParameter("@UpdateProcessStatus", UpdateProcessStatus);
sqlParam[3] = new SqlParameter("@CompanyID", (dt.Rows[i]["CompanyID"].ToString()));
DPrvdr.InsertDeleteUpdateDataStrProc("uspMAS500SOSER_SaveSOStatus", sqlParam);
}
catch (Exception ex)
{
throw ex;
}
}
}
catch (Exception ex)
{
LogMessage("Error while calling web service for Row Key : " + (dt.Rows[i]["RowKey"].ToString()) + " inner excep : " + ex.Message);
}
}
catch (Exception ex)
{
LogMessage("Error while calling web service for Row Key : " + (dt.Rows[i]["RowKey"].ToString()) + " outter excep : " + ex.Message);
}
}
return hashSODetails;
}
答案 0 :(得分:0)
DataTable dt =新的DPrvdr.GetDataSetSProc(“ uspMAS500SOSER_GetSO”)。Tables [0];