http://www.mono-project.com/MySQL update?

Erik Nordström Andersen <[email protected]>
Newsgroups gmane.comp.gnome.mono.documentation
Message-ID <[email protected]>
Hi

I hope this is the right place to suggest updates to the homepage.

I was playing with Mono and MySQL and needed an example to get going.
http://www.mono-project.com/MySQL provides an example using the ByteFX
library but states above that the ByteFX library is deprecated. Below I
suggest a new example using the MySQL connector (borrowed from MySQL.com):

using System;
using System.Data;
using MySql.Data.MySqlClient;

class MySqlExample
{
	public static void Main(string[] args)
	{
        string myConnectionString = "Database=test;Data
Source=localhost;User Id=user;Password=passwd";
	    string mySelectQuery = "SELECT id, name FROM customer";
	    MySqlConnection myConnection = new MySqlConnection(myConnectionString);
	    MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection);
	    myConnection.Open();
	    MySqlDataReader myReader;
	    myReader = myCommand.ExecuteReader();
	    // Always call Read before accessing data.
	    while (myReader.Read()) {
	       Console.WriteLine(myReader.GetInt32(0) + ", " +
myReader.GetString(1));
	    }
	    // always call Close when done reading.
	    myReader.Close();
	    // Close the connection when done with it.
	    myConnection.Close();
	}
}



The compile command should be:

mcs MySqlExample.cs -r:System.Data.dll -r:MySql.Data.dll

And running the program:

mono MySqlExample.exe


Let me know if I should provide this in another format, e.g. with markup
or as a patch to a source file I can access somewhere.

Kind regards,

Erik Andersen
_______________________________________________
Mono-docs-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-docs-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.