2015-01-29 2 views
0

참고로, 저는 이것을 처리 할 수있는 여러 가지 방법이 있다는 것을 알고 있습니다 만, 저는이 프로젝트에서이 특별한 방법으로 작업해야합니다.데이터 세트에 데이터 테이블을 추가하면 데이터 세트에 2 개의 동일한 테이블이 생성되므로 추가 할 수있는 또 다른 방법이 있습니까?

VS2010에서 DataSetGenerator로 만든 DataSet에서 DataSet (DS) 및 DataTable (DT)을 만든 다음 일부 데이터와 함께 DT에 행을 추가합니다. 그런 다음 DS에 행에 데이터가 포함 된 DT를 추가하려고합니다. Visual Studio의이 시점에서 다음 코드 행으로 넘어갈 때 데이터 셋 비주얼 라이저에 두 개의 동일하게 명명 된 테이블이있는 데이터 세트가 표시됩니다. 그러나 둘 중 하나에는 데이터가 있고 다른 하나에는 데이터가 없습니다. 이것은 아마 나를 대신하여 감독하는 것이지만 그것을 식별 할 수는 없습니다. 아직도 C#을 배우므로 도움이되지 않습니다. 어떤 도움을 주셔서 감사합니다!

OLD CODE

private string getStorageKey(string strStorageAccount) 
    { 
     DataSetStorageKeyDetails ds = new DataSetStorageKeyDetails(); 
     DataSetStorageKeyDetails.StorageKeyDetailsDataTable dt = new DataSetStorageKeyDetails.StorageKeyDetailsDataTable(); 
     string strStorageKey = ""; 

     dt.Rows.Add(strStorageAccount); 
     ds.Tables.Add(dt); 

     DataSet dsOut = ServiceEnclosed.InterfaceService("GetStorageKey", ds); 

     DataTable dtr = dsOut.Tables[0]; 
     DataSetStorageKeyDetails.StorageKeyDetailsRow dr = dt.First(); 
     strStorageKey = dr.StorageName;    

     return strStorageKey; 
    } 

NEW CODE

private string getStorageKey(string strStorageAccount) 
    { 
     DataSetStorageKeyDetails ds = new DataSetStorageKeyDetails(); 
     string strStorageKey = ""; 

     ds.StorageKeyDetails.Rows.Add(strStorageAccount); 
     DataSet dsOut = ServiceEnclosed.InterfaceService("GetStorageKey", ds); 

     DataTable dtr = new DataTable(); 
     dtr = dsOut.Tables[0]; 
     strStorageKey = dtr.Rows[0]["StorageKey"].ToString(); 

     return strStorageKey; 
    } 
+0

DataSetStorageKeyDetails 클래스 란 무엇입니까? 나는 그것을 위해 Google을 수색하고 그것에 관하여 어떤 정보도 찾아 내지 않았다. –

+0

@GregBurghardt, 죄송합니다. DataSet과 DataTable은 DataSetGenerator로 만든 것입니다. – Gmac

+0

변수 이름이 혼란 스럽습니다. 'ds' 변수는'DataSetStorageKeyDetails' 객체입니다. 'dt' 변수는'StorageKeyDetailsDataTable'이지만'ds'와'dt' 둘 다'DataSet'과'DataTable' 인 것처럼 사용합니다. DataSetStorageKeyDetails 및 StorageKeyDetailsDataTable 클래스가 무엇인지 알지 못하면 귀하의 질문에 답변 할 수 없습니다. –

답변

1

당신이 DataSetGenerator, 데이터 집합을 만들 때 사용자가 지정한 테이블이 자동으로 생성되어있는 데이터 집합을 만들 수 있습니다. 새 테이블을 추가 할 필요없이 이미 테이블에 액세스 할 수 있습니다.

private string getStorageKey(string strStorageAccount) 
    { 
     DataSetStorageKeyDetails ds = new DataSetStorageKeyDetails(); 
     string strStorageKey = ""; 

     ds.StorageKeyDetails.Rows.Add(strStorageAccount); 

     DataSet dsOut = ServiceEnclosed.InterfaceService("GetStorageKey", ds); 

     DataTable dtr = dsOut.Tables[0]; 
     strStorageKey = ds.StorageKeyDetails.Rows[0].StorageName;    

     return strStorageKey; 
    } 

테스팅되지 않은 코드이지만 올바른 방향으로 가리키고 있다고 생각합니다.

+0

도움을 주셔서 감사 드리며 조금 더 비틀었지만 올바른 길로 나를 돌려 보내 셨습니다. 마지막 작업 코드로 게시물을 편집합니다. 다른 질문에 대답하기 위해 dtr은 WCF에서 반환 된 값을 데이터 집합 대신 프로그램에서 데이터 테이블로 읽어야하기 때문에 또 다른 데이터 테이블입니다. – Gmac

관련 문제