DataRow.Item[] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 열에 저장된 데이터를 가져오거나 설정합니다.
오버로드
| Name | Description |
|---|---|
| Item[DataColumn] |
지정된 DataColumn에 저장된 데이터를 가져오거나 설정합니다. |
| Item[Int32] |
인덱스로 지정된 열에 저장된 데이터를 가져오거나 설정합니다. |
| Item[String] |
이름으로 지정된 열에 저장된 데이터를 가져오거나 설정합니다. |
| Item[DataColumn, DataRowVersion] |
지정된 에 저장된 DataColumn데이터의 지정된 버전을 가져옵니다. |
| Item[Int32, DataRowVersion] |
검색할 데이터의 인덱스 및 버전으로 지정된 열에 저장된 데이터를 가져옵니다. |
| Item[String, DataRowVersion] |
명명된 열에 저장된 데이터의 지정된 버전을 가져옵니다. |
Item[DataColumn]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
지정된 DataColumn에 저장된 데이터를 가져오거나 설정합니다.
public:
property System::Object ^ default[System::Data::DataColumn ^] { System::Object ^ get(System::Data::DataColumn ^ column); void set(System::Data::DataColumn ^ column, System::Object ^ value); };
public object this[System.Data.DataColumn column] { get; set; }
member this.Item(System.Data.DataColumn) : obj with get, set
Default Public Property Item(column As DataColumn) As Object
매개 변수
- column
- DataColumn
데이터를 포함하는 A DataColumn 입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
열이 이 테이블에 속하지 않습니다.
column null입니다.
삭제된 행에 값을 설정하려고 했습니다.
값과 열의 데이터 형식이 일치하지 않습니다.
예제
다음 예제에서는 속성을 사용하여 Item[] 특정 열 인덱스의 값을 가져와서 설정하는 방법을 보여 줍니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행에서 첫 번째 열의 값을 가져옵니다. 두 번째는 메서드에 인수로 전달된 값을 설정합니다.
Private Sub DataGrid1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim dataGridTable As DataTable = _
CType(DataGrid1.DataSource, DataTable)
' Set the current row using the RowNumber
' property of the CurrentCell.
Dim currentRow As DataRow = _
dataGridTable.Rows(DataGrid1.CurrentCell.RowNumber)
Dim column As DataColumn = dataGridTable.Columns(1)
' Get the value of the column 1 in the DataTable.
label1.Text = currentRow(column).ToString()
End Sub
Private Sub SetDataRowValue( _
ByVal grid As DataGrid, ByVal newVal As Object)
' Set the value of a column in the last row of a DataGrid.
Dim table As DataTable = CType(grid.DataSource, DataTable)
Dim row As DataRow = table.Rows(table.Rows.Count - 1)
Dim column As DataColumn = table.Columns("FirstName")
row(column)= newVal
End Sub
설명
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.
적용 대상
Item[Int32]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
인덱스로 지정된 열에 저장된 데이터를 가져오거나 설정합니다.
public:
property System::Object ^ default[int] { System::Object ^ get(int columnIndex); void set(int columnIndex, System::Object ^ value); };
public object this[int columnIndex] { get; set; }
member this.Item(int) : obj with get, set
Default Public Property Item(columnIndex As Integer) As Object
매개 변수
- columnIndex
- Int32
열의 인덱스(0부터 시작하는 인덱스)입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
삭제된 행에 값을 설정하려고 할 때 발생합니다.
columnIndex 인수가 범위를 벗어났습니다.
예제
다음 예제에서는 속성을 사용하여 Item[] 특정 열 인덱스의 값을 가져와서 설정하는 방법을 보여 줍니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행에서 첫 번째 열의 값을 가져옵니다.
private void DataGrid1_Click(object sender,
System.EventArgs e)
{
// Get the DataTable the grid is bound to.
DataGrid thisGrid = (DataGrid) sender;
DataTable table = (DataTable) thisGrid.DataSource;
DataRow currentRow =
table.Rows[thisGrid.CurrentCell.RowNumber];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow[1]);
// You can also use the name of the column:
// Console.WriteLine(currentRow["FirstName"])
}
private void SetDataRowValue(DataGrid grid, object newValue)
{
// Set the value of the last column in the last row of a DataGrid.
DataTable table;
table = (DataTable) grid.DataSource;
DataRow row;
// Get last row
row = (DataRow)table.Rows[table.Rows.Count-1];
// Set value of last column
row[table.Columns.Count-1] = newValue;
}
Private Sub DataGrid1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Get the DataTable the grid is bound to.
Dim thisGrid As DataGrid = CType(sender, DataGrid)
Dim table As DataTable = CType(thisGrid.DataSource, DataTable)
Dim currentRow As DataRow = _
table.Rows(thisGrid.CurrentCell.RowNumber)
' Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow(1))
' You can also use the name of the column:
' Console.WriteLine(currentRow("FirstName"))
End Sub
Private Sub SetDataRowValue( _
ByVal grid As DataGrid, ByVal newValue As Object)
' Set the value of the last column in the last row of a DataGrid.
Dim table As DataTable
table = CType(grid.DataSource, DataTable)
Dim row As DataRow
row = table.Rows(table.Rows.Count-1)
row(table.Columns.Count-1) = newValue
End Sub
설명
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.
적용 대상
Item[String]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
이름으로 지정된 열에 저장된 데이터를 가져오거나 설정합니다.
public:
property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ columnName); void set(System::String ^ columnName, System::Object ^ value); };
public object this[string columnName] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(columnName As String) As Object
매개 변수
- columnName
- String
열 이름입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
지정한 columnName 열을 찾을 수 없습니다.
삭제된 행에 값을 설정하려고 할 때 발생합니다.
으로 설정된 열 AllowDBNull 에 null 값을 삽입하려고 할 때 발생합니다 false.
예제
다음 예제에서는 속성을 사용하여 Item[] 특정 열 인덱스의 값을 가져와서 설정하는 방법을 보여 줍니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행에서 첫 번째 열의 값을 가져옵니다. 두 번째는 메서드에 인수로 전달된 값을 설정합니다.
private void DataGrid1_Click(
object sender, System.EventArgs e)
{
// Get the DataTable the grid is bound to.
DataGrid thisGrid = (DataGrid) sender;
DataTable table = (DataTable) thisGrid.DataSource;
DataRow currentRow =
table.Rows[thisGrid.CurrentCell.RowNumber];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow["FirstName"]);
// You can also use the index:
// Console.WriteLine(currentRow[1]);
}
private void SetDataRowValue(
DataGrid grid, object newValue)
{
// Set the value of the first column in
// the last row of a DataGrid.
DataTable table = (DataTable) grid.DataSource;
DataRow row = table.Rows[table.Rows.Count-1];
row["FirstName"] = newValue;
}
Private Sub DataGrid1_Click( _
sender As Object, e As System.EventArgs)
' Get the DataTable the grid is bound to.
Dim thisGrid As DataGrid = CType(sender, DataGrid)
Dim table As DataTable = _
CType(thisGrid.DataSource, DataTable)
Dim currentRow As DataRow = _
table.Rows(thisGrid.CurrentCell.RowNumber)
' Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow("FirstName"))
' You can also use the index:
' Console.WriteLine(currentRow(1).ToString())
End Sub
Private Sub SetDataRowValue( _
grid As DataGrid, newValue As Object)
' Set the value of the first column in
' the last row of a DataGrid.
Dim table As DataTable = _
CType(grid.DataSource, DataTable)
Dim row As DataRow
row = table.Rows((table.Rows.Count - 1))
row("FirstName") = newValue
End Sub
설명
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.
적용 대상
Item[DataColumn, DataRowVersion]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
지정된 에 저장된 DataColumn데이터의 지정된 버전을 가져옵니다.
public:
property System::Object ^ default[System::Data::DataColumn ^, System::Data::DataRowVersion] { System::Object ^ get(System::Data::DataColumn ^ column, System::Data::DataRowVersion version); };
public object this[System.Data.DataColumn column, System.Data.DataRowVersion version] { get; }
member this.Item(System.Data.DataColumn * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(column As DataColumn, version As DataRowVersion) As Object
매개 변수
- column
- DataColumn
DataColumn 열에 대한 정보가 들어 있는 A입니다.
- version
- DataRowVersion
원하는 행 버전을 지정하는 값 중 DataRowVersion 하나입니다. 가능한 값은 Default, Original, Current 및 Proposed입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
열이 테이블에 속하지 않습니다.
인수에 column null이 포함됩니다.
행에 이 버전의 데이터가 없습니다.
예제
다음 예제에서는 컨트롤에서 DataGrid 클릭한 셀의 현재 값을 가져옵니다.
private void DataGrid1_Click(object sender,
System.EventArgs e)
{
DataTable dataGridTable =
(DataTable)DataGrid1.DataSource;
// Set the current row using the RowNumber
// property of the CurrentCell.
DataRow currentRow = dataGridTable.Rows[DataGrid1.CurrentCell.RowNumber];
DataColumn column = dataGridTable.Columns[1];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow[column, DataRowVersion.Current]);
}
Private Sub DataGrid1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dataGridTable As DataTable = _
CType(DataGrid1.DataSource, DataTable)
' Set the current row using the RowNumber
' property of the CurrentCell.
Dim currentRow As DataRow = dataGridTable.Rows( _
DataGrid1.CurrentRowIndex)
Dim column As DataColumn = dataGridTable.Columns(1)
' Get the value of the column 1 in the DataTable.
label1.Text = currentRow(column, _
DataRowVersion.Current).ToString()
End Sub
설명
속성 version 과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다.
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.
추가 정보
적용 대상
Item[Int32, DataRowVersion]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
검색할 데이터의 인덱스 및 버전으로 지정된 열에 저장된 데이터를 가져옵니다.
public:
property System::Object ^ default[int, System::Data::DataRowVersion] { System::Object ^ get(int columnIndex, System::Data::DataRowVersion version); };
public object this[int columnIndex, System.Data.DataRowVersion version] { get; }
member this.Item(int * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(columnIndex As Integer, version As DataRowVersion) As Object
매개 변수
- columnIndex
- Int32
열의 인덱스(0부터 시작하는 인덱스)입니다.
- version
- DataRowVersion
원하는 행 버전을 지정하는 값 중 DataRowVersion 하나입니다. 가능한 값은 Default, Original, Current 및 Proposed입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
columnIndex 인수가 범위를 벗어났습니다.
값과 열의 데이터 형식이 일치하지 않습니다.
행에 이 버전의 데이터가 없습니다.
삭제된 행에 값을 설정하려고 했습니다.
예제
다음 예제에서는 개체의 속성을 통해 Item[] 열의 DataRow 현재 값을 가져옵니다.
Private Sub DataGrid1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set the current row using the RowNumber property of the CurrentCell.
Dim currentRow As DataRow = CType(DataGrid1.DataSource, DataTable). _
Rows(DataGrid1.CurrentCell.RowNumber)
' Get the value of the column 1 in the DataTable.
label1.Text = currentRow(1, DataRowVersion.Current).ToString()
End Sub
설명
메서드를 호출 BeginEdit 한 후에만 행을 만들거나 업데이트할 수 있습니다. 마찬가지로 EndEdit 편집을 커밋하려면 메서드를 호출해야 합니다. 메서드를 EndEdit 호출한 후 메서드를 AcceptChanges 호출하기 전에 원래 값과 새로 제안된 값의 내부 표현이 저장됩니다. 따라서 호출할 때까지 인수를 AcceptChangesversion 사용하여 필요한 DataRowVersion.OriginalDataRowVersion.Proposed열 값의 버전을 지정할 수 있습니다. 그러나 메서드를 AcceptChanges 호출하는 즉시 열의 버전이 .로 되돌아갑니다 DataRowVersion.Original. 행이 새 행인 경우 매개 변수를 전달 DataRowVersion.Default 하여 열의 기본값을 검색할 수도 있습니다. 전달할 DataRowVersion.Current때 속성은 버전에 관계없이 현재 값을 반환합니다.
메모
이 메서드는 BeginEdit 데이터 바인딩된 컨트롤의 값을 변경하거나 DataRow 개체가 추가 DataRowCollectionEndEdit 되면 암시적으로 호출됩니다. 메서드는 개체의 메서드AcceptChanges, DataRowAcceptChanges 개체 메서드 DataTable 또는 CancelEdit 메서드를 호출할 때 암시적으로 호출됩니다.
반면, DataRowVersion 열거형 Current 은 메서드가 호출된 후 EndEdit 데이터의 버전을 반환합니다.
인수를 version 속성과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다. 이 속성은 RowState 상위 DataTable행을 기준으로 전체 행의 상태를 설명합니다.
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.
적용 대상
Item[String, DataRowVersion]
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
- Source:
- DataRow.cs
명명된 열에 저장된 데이터의 지정된 버전을 가져옵니다.
public:
property System::Object ^ default[System::String ^, System::Data::DataRowVersion] { System::Object ^ get(System::String ^ columnName, System::Data::DataRowVersion version); };
public object this[string columnName, System.Data.DataRowVersion version] { get; }
member this.Item(string * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(columnName As String, version As DataRowVersion) As Object
매개 변수
- columnName
- String
열 이름입니다.
- version
- DataRowVersion
원하는 행 버전을 지정하는 값 중 DataRowVersion 하나입니다. 가능한 값은 Default, Original, Current 및 Proposed입니다.
속성 값
Object 데이터가 들어 있는 항목입니다.
예외
지정한 columnName 열을 찾을 수 없습니다.
값과 열의 데이터 형식이 일치하지 않습니다.
행에 이 버전의 데이터가 없습니다.
행이 삭제되었습니다.
예제
다음 예제에서는 컨트롤의 클릭된 셀 DataGrid 에서 데이터의 현재 버전을 가져옵니다.
private void DataGrid1_Click(object sender, System.EventArgs e)
{
// Set the current row using the RowNumber
// property of the CurrentCell.
DataRow currentRow =
((DataTable)(DataGrid1.DataSource)).
Rows[DataGrid1.CurrentCell.RowNumber];
// Print the current value of the column named "FirstName."
Console.WriteLine(currentRow["FirstName",
DataRowVersion.Current]);
}
Private Sub DataGrid1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set the current row using the RowNumber property
' of the CurrentCell.
Dim currentRow As DataRow = _
CType(DataGrid1.DataSource, DataTable). _
Rows(DataGrid1.CurrentCell.RowNumber)
' Print the current value of the column named "FirstName."
Console.WriteLine(currentRow("FirstName", _
DataRowVersion.Current).ToString())
End Sub
설명
버전은 속성과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다. 이 속성은 RowState 상위 DataTable행을 기준으로 전체 행의 상태를 설명합니다.
속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.
즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.