DataSet 개체는 ADO.NET 연결이 끊긴 분산 데이터 시나리오를 지원하는 데 핵심적인 요소입니다. DataSet 개체는 데이터 원본에 관계없이 일관된 관계형 프로그래밍 모델을 제공하는 데이터의 메모리 상주 표현입니다. XML 데이터와 함께 여러 다른 데이터 원본과 함께 사용하거나 애플리케이션에 대한 로컬 데이터를 관리할 수 있습니다. DataSet 개체는 관련 테이블, 제약 조건 및 테이블 간의 관계를 포함하여 전체 데이터 집합을 나타냅니다. 데이터 세트 개체의 데이터 저장 및 노출 기능이 다양하기 때문에 해당 데이터에 대한 보고가 발생하기 전에 데이터를 처리하고 DataSet 개체로 변환하는 경우가 많습니다.
Reporting Services 데이터 처리 확장 프로그램을 사용하면 외부 애플리케이션에서 만든 모든 사용자 지정 DataSet 개체를 통합할 수 있습니다. 이를 위해 Reporting Services에서 DataSet 개체와 보고서 서버 간의 브리지처럼 작동하는 사용자 지정 데이터 처리 확장 프로그램을 만듭니다. 이 DataSet 개체를 처리하기 위한 대부분의 코드는 사용자가 만든 DataReader 클래스에 포함되어 있습니다.
DataSet 개체를 보고서 서버에 노출하는 첫 번째 단계는 DataSet 개체를 채울 수 있는 DataReader 클래스에서 공급자별 메서드를 구현하는 것입니다. 다음 예제에서는 DataReader 클래스에서 공급자별 메서드를 사용하여 정적 데이터를 DataSet 개체에 로드하는 방법을 보여 줍니다.
'Private members of the DataReader class
Private m_dataSet As System.Data.DataSet
Private m_currentRow As Integer
'Method to create a dataset
Friend Sub CreateDataSet()
' Create a dataset.
Dim ds As New System.Data.DataSet("myDataSet")
' Create a data table.
Dim dt As New System.Data.DataTable("myTable")
' Create a data column and set various properties.
Dim dc As New System.Data.DataColumn()
dc.DataType = System.Type.GetType("System.Decimal")
dc.AllowDBNull = False
dc.Caption = "Number"
dc.ColumnName = "Number"
dc.DefaultValue = 25
' Add the column to the table.
dt.Columns.Add(dc)
' Add 10 rows and set values.
Dim dr As System.Data.DataRow
Dim i As Integer
For i = 0 To 9
dr = dt.NewRow()
dr("Number") = i + 1
' Be sure to add the new row to the DataRowCollection.
dt.Rows.Add(dr)
Next i
' Fill the dataset.
ds.Tables.Add(dt)
' Use a private variable to store the dataset in your
' DataReader.
m_dataSet = ds
' Set the current row to -1.
m_currentRow = - 1
End Sub 'CreateDataSet
// Private members of the DataReader class
private System.Data.DataSet m_dataSet;
private int m_currentRow;
// Method to create a dataset
internal void CreateDataSet()
{
// Create a dataset.
System.Data.DataSet ds = new System.Data.DataSet("myDataSet");
// Create a data table.
System.Data.DataTable dt = new System.Data.DataTable("myTable");
// Create a data column and set various properties.
System.Data.DataColumn dc = new System.Data.DataColumn();
dc.DataType = System.Type.GetType("System.Decimal");
dc.AllowDBNull = false;
dc.Caption = "Number";
dc.ColumnName = "Number";
dc.DefaultValue = 25;
// Add the column to the table.
dt.Columns.Add(dc);
// Add 10 rows and set values.
System.Data.DataRow dr;
for(int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["Number"] = i + 1;
// Be sure to add the new row to the DataRowCollection.
dt.Rows.Add(dr);
}
// Fill the dataset.
ds.Tables.Add(dt);
// Use a private variable to store the dataset in your
// DataReader.
m_dataSet = ds;
// Set the current row to -1.
m_currentRow = -1;
}
public bool Read()
{
m_currentRow++;
if (m_currentRow >= m_dataSet.Tables[0].Rows.Count)
{
return (false);
}
else
{
return (true);
}
}
public int FieldCount
{
// Return the count of the number of columns, which in
// this case is the size of the column metadata
// array.
get { return m_dataSet.Tables[0].Columns.Count; }
}
public string GetName(int i)
{
return m_dataSet.Tables[0].Columns[i].ColumnName;
}
public Type GetFieldType(int i)
{
// Return the actual Type class for the data type.
return m_dataSet.Tables[0].Columns[i].DataType;
}
public Object GetValue(int i)
{
return m_dataSet.Tables[0].Rows[m_currentRow][i];
}
public int GetOrdinal(string name)
{
// Look for the ordinal of the column with the same name and return it.
// Returns -1 if not found.
return m_dataSet.Tables[0].Columns[name].Ordinal;
}
데이터 세트를 만들거나 검색한 후에는 DataReader 클래스의 Read, GetValue, GetName, GetOrdinal, GetFieldType 및 FieldCount 멤버의 구현에서 DataSet 개체를 사용할 수 있습니다.
또한 참조하십시오
Reporting Services 확장
데이터 처리 확장 프로그램 구현
Reporting Services 확장 라이브러리