2014-12-19 1 views
1

아래 코드에서 데이터 테이블에 값과 다른 빈 데이터 테이블 Orderdbl이 있고 3 개의 열을 추가하는 정적 메서드가 있습니다.데이터 테이블의 값을 확인하고 데이터 테이블에 값을 추가하려면

이제 내 목표는 locationid,productid,quantity을 정적 방법으로 보냅니다.
productid의 데이터 테이블에 dtGrid이 있는지 확인하고 값이없는 경우 다른 데이터 테이블 Orderdbl을 확인한 다음 값이없는 경우 데이터 테이블 Orderdbl에 값을 추가하고 세션에 저장해야합니다. Pls이 날 도와 줘요. 여기

[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

죄송합니다 친구를 추가 할 경우 dtGrid 테이블에 보면 want.First 것입니다. 여기에 아무도 코드를 작성하지 않습니다. 혹시 이상한 오류가 발생하거나 문제가있는 경우 사람들이 아이디어를 도울 것입니다. – Thangadurai

+0

@ Thangadurai 내가 코드 pls을 작성했습니다 실수는 무엇입니까 – Developer

+0

무엇이 오류입니까? – Mairaj

답변

0

를 찾을 수 없습니다 값이 두 번째 데이터 테이블에보고 여전히보다 찾을 수없는 경우 새 행을

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

datatable에서 productid를 확인하고 싶습니다. dtGrid에 값이 없으면 다른 datatable Orderdbl과 값을 비교하여 값을 확인한 다음 Dataatable Orderdbl에 값을 추가하고 세션에 저장합니다. – Developer

+0

Session [ "OrderForm"]에 값을 할당하고 세션 [ "VSOrderForm"]에서 읽는 중입니까? – Mairaj

+0

ProductID를 전달하여 세션 datatable과 세션 [ "OrderForm"] – Developer

관련 문제