Getting multiple MySQL Query results on Visual C# Console App -
I am trying to print results from a MySQL query on a Visual C # console application. I'm able to get more than one column on a line, as you can see below, but I'm wondering how I can get many results (rows). You can see, there are more records in my table that meet the query criteria. Can somebody help me out?
class program {static zero main (string [] args) {string ConnectionString = "Server = localhost; Database = world; Uid = root; Pwd = password"; // Connection string giving MySqlConnection connection = new MySqlConnection (ConnectionString); MySqlCommand CMD = connection.CreateCommand (); Cmd.CommandText = "Select name, city from population where population> 4000000"; Try {connection.Open (); } Hold (Exception Pre) {Console.WriteLine (ex.Message); } MySqlDataReader Reader = cmd.ExecuteReader (); While (reader.Read ()) {Console.WriteLine ("City name is:" + Reader ["name"]. ToString () + "" + Reader ["Population"]. ToString ()); Console.Read (); }}
Your call to the console. Read () while blocking the loop, so you're printing only one line for the console, and then waiting for user input.
Cheers
Comments
Post a Comment