C# Read Data From Database
Posted by tech on
January 15, 2009
This code lets you read data from the database. By default, MS SQL is mainly used in tutorials regarding .NET. This code connects to a MySQL database. If you are using MS SQL, just rename the classes that starts with MySQL to SQL. This code assumes that you already have a connection object in hand.
MySqlConnection con = ...; try { MySqlCommand cmd = con.createCommand(); cmd.CommandText = "select username from users where username = 'me'"; con.Open(); MySqlDataReader dr = cmd.executeReader(); if (dr.Read()) { Console.WriteLine("username = " + dr["username"]); } } catch (Exception e) { } finally { if (con != null) { con.Close(); con.Dispose(); } }









January 15th, 2009 at 11:12 am
I wonder why you never answer any of my question about your topic?
My Daily Thoughts
Blogger”s Recollections
Array Of Hopes
January 15th, 2009 at 7:20 pm
hi tey, i wonder why you don’t see my replies. i do
. i reply them here in my posts.