2014-12-19 100 views
1

在下面的代码中,我有一个静态方法,其中有一个数据表的值和另一个空数据表Orderdbl并添加3列。检查数据表中的值并将数值添加到数据表中

现在我的目标是发送locationid,productid,quantity到静态方法。
现在我想检查productid在数据表dtGrid如果它没有值,并且它应该与另一个数据表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; 
      } 
     } 
    } 
} 
+0

对不起朋友。这里没有人会为你写代码。如果您遇到任何奇怪的错误或遇到一些问题,那么人们会帮助您解决他们的想法。 – Thangadurai 2014-12-19 11:57:31

+0

@Thangadurai我写的代码请告诉我是错误 – Developer 2014-12-19 12:00:22

+0

什么是错误? – Mairaj 2014-12-19 12:02:26

回答

0

这里是你want.First看什么dtGrid表,如果值没有发现将查找第二数据表中,如果还没有发现比添加新行

public static void InsertData(string LocationID, string ProductID, string Quantity) 
{ 
    MastersClient objIndent = new MastersClient(); 
    DataTable dtGrid = (DataTable)HttpContext.Current.Session["VSOrderForm"]; 
    DataTable Orderdbl = (DataTable)HttpContext.Current.Session["OrderForm"]; 
    // DataSet ds = objIndent.CheckForExistingOrder(Int32.Parse(LocationID), ProductID); 


    //Check in first table 
    var DataCheck = dtGrid.Select("ProductID = '" + ProductID + "'"); 
    if (DataCheck.Length != 0) 
    { 
     // do something... 
    } 
    //if (ds != null && ds.Tables.Count > 0) 
    //{ 
    //} 
    else 
    { 
     //Not found in first now check in second talbe 
     if (Orderdbl != null) 
     { 
      string FilterCond1 = "ProductID=" + ProductID; 
      DataRow[] newrow = Orderdbl.Select(FilterCond1); 
      //If Length > 0 it means found in second table, 
      if (newrow.Length > 0) 
      { 

       for (int i = 0; i < newrow.Length; i++) 
       { 
        if (newrow[i]["ProductID"].ToString() == ProductID) 
        { 
         // YOUR CODE HERE 
        } 
       } 
      } 
      else 
      { 
       //Not found in second talbe now add new row 

       DataRow row = Orderdbl.NewRow(); 
       //if (string.IsNullOrEmpty((string)Orderdbl.Rows[i][j].value)) 
       row["LocationID"] = LocationID; 
       row["ProductID"] = ProductID; 
       Orderdbl.Rows.Add(row); 
       HttpContext.Current.Session["OrderForm"] = Orderdbl; 
      } 
     } 
     else 
     { 
      //This will run first time when session has no value. 
      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)) 
      row["LocationID"] = LocationID; 
      row["ProductID"] = ProductID; 
      Orderdbl.Rows.Add(row); 
      HttpContext.Current.Session["OrderForm"] = Orderdbl; 
     } 


    } 
} 
+0

我想检查produatd在数据表中dtGrid,如果它没有值,并且它应该检查另一个数据表Orderdbl,如果它没有值然后将值添加到数据表Orderdbl并将它存储在会话 – Developer 2014-12-19 12:16:28

+0

中您已将值赋给Session [“OrderForm”]和您正在阅读Session [“VSOrderForm”]是这样吗? – Mairaj 2014-12-19 12:18:14

+0

我必须通过传递productid并存储到Session [“OrderForm”]来检查会话数据表。 – Developer 2014-12-19 12:25:29

相关问题