【发布时间】:2014-12-19 11:40:26
【问题描述】:
在下面的代码中,我有一个静态方法,其中我有一个带有值的数据表和另一个空数据表 Orderdbl 并添加 3 列。
现在我的目标是将locationid,productid,quantity 发送到静态方法。
现在我想检查数据表dtGrid 中的productid 是否没有该值,如果它没有该值,它应该检查另一个数据表Orderdbl 然后将值添加到数据表Orderdbl 并将其存储在一个会话。请帮我解决这个问题。
[WebMethod(EnableSession = true)]
public static void InsertData(string LocationID, string ProductID, string Quantity)
{
MastersClient objIndent = new MastersClient();
DataTable dtGrid = (DataTable)HttpContext.Current.Session["VSOrderForm"];
// DataSet ds = objIndent.CheckForExistingOrder(Int32.Parse(LocationID), ProductID);
var DataCheck = dtGrid.Select("ProductID = '" + ProductID + "'");
if (DataCheck.Length != 0)
{
// do something...
}
//if (ds != null && ds.Tables.Count > 0)
//{
//}
else
{
DataTable Orderdbl = new DataTable();
Orderdbl.Columns.Add("LocationID", typeof(string));
Orderdbl.Columns.Add("ProductID", typeof(string));
Orderdbl.Columns.Add("Quantity", typeof(string));
DataRow row = Orderdbl.NewRow();
//if (string.IsNullOrEmpty((string)Orderdbl.Rows[i][j].value))
if (Orderdbl == null)
{
row["LocationID"] = LocationID;
row["ProductID"] = ProductID;
Orderdbl.Rows.Add(row);
HttpContext.Current.Session["OrderForm"] = Orderdbl;
}
else
{
string FilterCond1 = "ProductID=" + ProductID;
DataRow[] newrow = Orderdbl.Select(FilterCond1);
if (newrow.Length > 0)
{
for (int i = 0; i < newrow.Length; i++)
{
if (newrow[i]["ProductID"].ToString() == ProductID)
{
// YOUR CODE HERE
}
}
}
else
{
row["LocationID"] = LocationID;
row["ProductID"] = ProductID;
Orderdbl.Rows.Add(row);
HttpContext.Current.Session["OrderForm"] = Orderdbl;
}
}
}
}
【问题讨论】:
-
对不起朋友。这里没有人会为您编写代码。如果您遇到任何奇怪的错误或遇到一些问题,那么人们会帮助您提出他们的想法。
-
@Thangadurai 我写了代码请告诉我是错误
-
@Mairaj Ahmad 首先我试图将值存储在数据表中并在下次存储另一个值时保持会话中数据表计数为 0 我想将所有值存储在数据表中并存储在会话中