Advertisement
solidsnake

C#MySQLConnector

May 15th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. namespace ConsoleApplication4
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             MySqlConnection conn = new MySqlConnection("Server = localhost;Database=inv;Uid=root;Pwd=root;");
  8.  
  9.             conn.Open();
  10.  
  11.             MySqlCommand cmd = new MySqlCommand("SELECT * FROM foxhound;", conn);
  12.             MySqlDataReader read = cmd.ExecuteReader();
  13.             while (read.Read())
  14.             {
  15.                 Console.WriteLine("{0}", read.GetString(0));
  16.             }
  17.         Object ret = cmd.ExecuteScalar();
  18.         Console.WriteLine("# of lines: " + ret.ToString());
  19.  
  20.             conn.Close();
  21.             Console.ReadKey();
  22.         }
  23.     }
  24. }
  25.  
  26. to change, use cmd.ExecuteNonQuery();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement