Advertisement
Guest User

Untitled

a guest
May 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class Tutorial2
  2. {
  3. public static void Main()
  4. {
  5. string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
  6. MySqlConnection conn = new MySqlConnection(connStr);
  7. try
  8. {
  9. Console.WriteLine("Connecting to MySQL...");
  10. conn.Open();
  11.  
  12. string sql = "SELECT Name, HeadOfState FROM Country WHERE Continent='Oceania'";
  13. MySqlCommand cmd = new MySqlCommand(sql, conn);
  14. MySqlDataReader rdr = cmd.ExecuteReader();
  15.  
  16. while (rdr.Read())
  17. {
  18. Console.WriteLine(rdr[0]+" -- "+rdr[1]);
  19. }
  20.  
  21. rdr.Close();
  22. conn.Close();
  23. }
  24. catch (Exception ex)
  25. {
  26. Console.WriteLine(ex.ToString());
  27. }
  28. Console.WriteLine("Done.");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement