Results 1 to 2 of 2

Thread: MySQL and mono

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    3

    MySQL and mono

    How do I use MySQL with mono?

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: MySQL and mono

    Ehhh hmmm...?

    What do you mean. Example:


    Code:
     using System;
     using System.Data;
     using ByteFX.Data.MySqlClient;
     
     public class Test 
     {
        public static void Main(string[] args)
        {
           string connectionString = 
              "Server=localhost;" +
              "Database=test;" +
              "User ID=myuserid;" +
              "Password=mypassword;";
           IDbConnection dbcon;
           dbcon = new MySqlConnection(connectionString);
           dbcon.Open();
           IDbCommand dbcmd = dbcon.CreateCommand();
           // requires a table to be created named employee
           // with columns firstname and lastname
           // such as,
           //        CREATE TABLE employee (
           //           firstname varchar(32),
           //           lastname varchar(32));
           string sql = 
               "SELECT firstname, lastname " +
               "FROM employee";
           dbcmd.CommandText = sql;
           IDataReader reader = dbcmd.ExecuteReader();
           while(reader.Read()) {
                string FirstName = (string) reader["firstname"];
                string LastName = (string) reader["lastname"];
                Console.WriteLine("Name: " + 
                      FirstName + " " + LastName);
           }
           // clean up
           reader.Close();
           reader = null;
           dbcmd.Dispose();
           dbcmd = null;
           dbcon.Close();
           dbcon = null;
        }
     }

    The mono page it self is a pretty good resource on anything mono related. And they have their own MySQL page:

    http://www.go-mono.com/mysql.html


    - ØØ -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width