Read Method (SQLiteDataReader)
|
|---|
'Declaration
Public Overrides Function Read() As Boolean |
|
|---|
public override bool Read() |
Return Value
true if there are more rows; otherwise, false.
The following example creates a
SQLiteConnection, a
SQLiteCommand, and a
SQLiteDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
SQLiteDataReader, then the
SQLiteConnection.
|
|---|
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT DeptNo, DName FROM Dept";
SQLiteConnection sqLiteConnection = new SQLiteConnection(myConnString);
SQLiteCommand sqLiteCommand = new SQLiteCommand(mySelectQuery,sqLiteConnection);
sqLiteConnection.Open();
SQLiteDataReader sqLiteReader;
sqLiteReader = sqLiteCommand.ExecuteReader();
// Always call Read before accessing data.
while (sqLiteReader.Read()) {
Console.WriteLine(sqLiteReader.GetInt32(0) + ", " + sqLiteReader.GetString(1));
}
// always call Close when done reading.
sqLiteReader.Close();
// Close the connection when done with it.
sqLiteConnection.Close();
} |
|
|---|
Public Sub ReadMyData(myConnString As String)
Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Dept"
Dim sqLiteConnection As New SQLiteConnection(myConnString)
Dim sqLiteCommand As New SQLiteCommand(mySelectQuery, sqLiteConnection)
sqLiteConnection.Open()
Dim sqLiteReader As SQLiteDataReader
sqLiteReader = sqLiteCommand.ExecuteReader()
' Always call Read before accessing data.
While sqLiteReader.Read()
Console.WriteLine(sqLiteReader.GetInt32(0).ToString() + ", " _
+ sqLiteReader.GetString(1))
End While
' always call Close when done reading.
sqLiteReader.Close()
' Close the connection when done with it.
sqLiteConnection.Close()
End Sub |