2014-02-21 3 views
2

행 수가 제한되도록 다음 코드를 수정해야합니다.행 제한이있는 데이터 어댑터로 데이터 세트 채우기

// create the connection 
OracleConnection conn = new OracleConnection("Data Source=oracledb; 
    User Id=UserID;Password=Password;"); 

// create the command for the stored procedure 
OracleCommand cmd = new OracleCommand(); 
cmd.Connection = conn; 
cmd.CommandText = "SELECT_JOB_HISTORY.GetJobHistoryByEmployeeId"; 
cmd.CommandType = CommandType.StoredProcedure; 

// add the parameters for the stored procedure including the REF CURSOR 
// to retrieve the result set 
cmd.Parameters.Add("p_employee_id", OracleType.Number).Value = 101; 
cmd.Parameters.Add("cur_JobHistory", OracleType.Cursor).Direction = 
    ParameterDirection.Output; 

// createt the DataAdapter from the command and use it to fill the 
// DataSet 
OracleDataAdapter da = new OracleDataAdapter(cmd); 
DataSet ds = new DataSet(); 
da.Fill(ds);//Here is where I need to limit the rows 

최대 개수를 채우는 방법이 있습니다.

public int Fill( DataSet dataSet, int startRecord, int maxRecords, string srcTable )

그러나, 나는 srcTable에 전달해야하는지 모른다. 내 저장된 proc에는 하나의 REF_CURSOR (OUT TYPES.REF_CURSOR)이 있습니다.

도움을 주시면 감사하겠습니다.

답변

1

srcTable 매개 변수는 DataTable의 이름이고 DataSet 개체입니다.

편집 : 당신이 명시 적으로 하나를 작성하지 않은 경우 Fill를 호출 할 때

DataSet 개체가 자동으로 테이블을 추가합니다. 기본 이름은 "표"입니다. DataSet 개체 은 어떤 유형의 데이터로 채워지는지 걱정하지 않습니다. 여전히 DataTable을 생성합니다.

에 전화하기 전에 DataAdapter에 전화하십시오.

ds.Tables.Add("myTableName"); 

는 다음과 같이 적절한 오버로드 Fill() 메소드를 호출합니다 :

da.Fill(ds, 1, 1000, "myTableName"); 

아니면 그냥 경우가 Fill() 방법 중에 액세스 할 수 있도록 이름으로 DataSet에 빈 테이블 추가 테이블의 기본 이름을 사용하거나 작성한 테이블의 이름을 모를 경우 (의심스러운 경우) :

da.Fill(ds, 1, 1000, ds.Tables[0].TableName); 

Spcifica lly 예제를 사용하면 다음과 같이 표시됩니다.

OracleDataAdapter da = new OracleDataAdapter(cmd); 
DataSet ds = new DataSet(); 
ds.Tables.Add(); 
da.Fill(ds, 1, maxRowCount, ds.Tables[0].TableName);//Here is where I need to limit the rows 
+0

코드 조각에서 알 수 있듯이 데이터 세트에 추가 된 테이블이 없습니다. 출력은 커서입니다. – Jimmy

+0

'DataSet'을 임의의 데이터로 채우면 자동적으로'DataTable'이 생성되고 추가됩니다. 'Fill'을 지나서 디버거에있는'Tables' 속성을 봅니다. 테이블을 명시 적으로 delcare하지 않았기 때문에'ds.Tables [0] .TableName' 예제를 사용할 수 있습니다. –

+0

왜 코드를 던져서는 안됩니까? 방금 데이터 세트를 만들었고 그 당시에는 테이블이 없었습니다. 여전히 인덱스 0을 함수에 전달하려고합니다. – Jimmy

관련 문제