2014-12-19 96 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

相關問題