SqlDataReader.GetValues(Object[]) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Naplní pole objektů hodnotami sloupců aktuálního řádku.
public:
virtual int GetValues(cli::array <System::Object ^> ^ values);
public:
override int GetValues(cli::array <System::Object ^> ^ values);
public int GetValues(object[] values);
public override int GetValues(object[] values);
abstract member GetValues : obj[] -> int
override this.GetValues : obj[] -> int
override this.GetValues : obj[] -> int
Public Function GetValues (values As Object()) As Integer
Public Overrides Function GetValues (values As Object()) As Integer
Parametry
Návraty
Počet instancí Object v poli.
Implementuje
Příklady
Následující příklad ukazuje použití správné velikosti pole ke čtení všech hodnot z aktuálního řádku v zadaném SqlDataReaderřádku . Kromě toho ukázka ukazuje použití pole s pevnou velikostí, které může být menší nebo větší než počet dostupných sloupců.
private static void TestGetValues(SqlDataReader reader)
{
// Given a SqlDataReader, use the GetValues
// method to retrieve a full row of data.
// Test the GetValues method, passing in an array large
// enough for all the columns.
Object[] values = new Object[reader.FieldCount];
int fieldCount = reader.GetValues(values);
Console.WriteLine("reader.GetValues retrieved {0} columns.",
fieldCount);
for (int i = 0; i < fieldCount; i++)
Console.WriteLine(values[i]);
Console.WriteLine();
// Now repeat, using an array that may contain a different
// number of columns than the original data. This should work correctly,
// whether the size of the array is larger or smaller than
// the number of columns.
// Attempt to retrieve three columns of data.
values = new Object[3];
fieldCount = reader.GetValues(values);
Console.WriteLine("reader.GetValues retrieved {0} columns.",
fieldCount);
for (int i = 0; i < fieldCount; i++)
Console.WriteLine(values[i]);
}
Private Sub TestGetValues(ByVal reader As SqlDataReader)
' Given a SqlDataReader, use the GetValues
' method to retrieve a full row of data.
' Test the GetValues method, passing in an array large
' enough for all the columns.
Dim values(reader.FieldCount - 1) As Object
Dim fieldCount As Integer = reader.GetValues(values)
Console.WriteLine("reader.GetValues retrieved {0} columns.", _
fieldCount)
For i As Integer = 0 To fieldCount - 1
Console.WriteLine(values(i))
Next
Console.WriteLine()
' Now repeat, using an array that may contain a different
' number of columns than the original data. This should work correctly,
' whether the size of the array is larger or smaller than
' the number of columns.
' Attempt to retrieve three columns of data.
ReDim values(2)
fieldCount = reader.GetValues(values)
Console.WriteLine("reader.GetValues retrieved {0} columns.", _
fieldCount)
For i As Integer = 0 To fieldCount - 1
Console.WriteLine(values(i))
Next
End Sub
Poznámky
U většiny aplikací poskytuje tato metoda efektivní způsob načítání všech sloupců místo individuálního načítání jednotlivých sloupců.
Můžete předat Object pole, které obsahuje méně než počet sloupců obsažených ve výsledném řádku. Do pole se zkopíruje pouze množství dat Object , která pole obsahuje. Můžete také předat Object pole, jehož délka je větší než počet sloupců obsažených ve výsledném řádku.
Tato metoda vrátí pro DBNull sloupce databáze s hodnotou null.