The following example creates a
MySqlCommand, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source.
public void CreateMySqlDataReader(string mySelectQuery,string myConnectionString)
{
MySqlConnection myConnection = new MySqlConnection(myConnectionString);
MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection);
myCommand.Connection.Open();
MySqlDataReader myReader = myCommand.ExecuteReader();
try
{
while(myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
}
finally
{
myReader.Close();
myConnection.Close();
}
}
Public Sub CreateMySqlDataReader(mySelectQuery As String, _
myConnectionString As String)
Dim myConnection As New MySqlConnection(myConnectionString)
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
myCommand.Connection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Console.WriteLine(myReader.GetString(0))
End While
Finally
myReader.Close()
myConnection.Close()
End Try
End Sub