Getting C# and mySQL to play together

with C# / mySQL connector / 2008-01-28

There's plenty of good articles online about getting the busy with C# / mySQL connector. Others include this one at nystic.com, and this one at bitdaddys.com. This is meant to be a sort of "Hello, World" set of instructions.

  1. Download and install the Connector/Net software from MySQL.
  2. In a project in Visual Studio, add a reference to MySql.Data. Project > Add Reference, scroll down and select.
  3. The namespace can be added to your project with: using MySql.Data.MySqlClient;

The following code exemplifies usage of the mySQL component. On a form with a button and a text box:

private void button1_Click(object sender, EventArgs e) {

string Server = "your_server";

string Database = "your_database";

string Username = "your_user";

string Password = "your_password";

string Table = "your_table";

string ConnectionString = "SERVER=" + Server + ";DATABASE=" + Database + ";UID=" + Username + ";PASSWORD=" + Password;

MySqlConnection connection = new MySqlConnection(ConnectionString);

MySqlCommand command = connection.CreateCommand();

MySqlDataReader Reader;

command.CommandText = "select * from " + Table;

connection.Open();

Reader = command.ExecuteReader();

textBox1.Text = "";

while (Reader.Read())

textBox1.Text += Reader.GetValue(i).ToString() + "n";

connection.Close();

}

TI-83 Plus Black Scholes (914)

Plug n play / 2009-06-16

A sloppy implementation of Black Scholes on the TI-83 Plus. Read.

Getting C# and mySQL to play together (1188)

with C# / mySQL connector / 2008-01-28

For that project where using MS SQL isn't going to cut it. Read.

Anatomy of a Major League Baseball tryout (2163)

"Ohhh. Let me see that." / 2007-03-12

For the most part, we took it seriously. Read.

Ubuntu 6.06 LTS (Dapper Drake) on Acer Travelmate C110 (13688)

It's thin, it's light. It's a tablet. / 2006-10-18

There's nothing cooler than a really small machine running linux. This is a collection of notes from the install, setup, and tweaking of the system running Ubuntu 6.06 LTS (Dapper Drake). It's probably a little over verbose. Read.

Laptop Advice (1760)

Thinkpads vs Dell vs HPQ vs The World / 2006-05-25

Hey Mike Sklut, you're a computer nerd, what kind of laptop should I get? Read.

Caesar Salad (1735)

How it's done / 2006-01-22

The Grossi Caesar salad. Read.

Manually mapping a Windows key on a Thinkpad (2874)

Editing with the Windows registry / 2005-08-12

Thinkpad - for players. But what about a Windows key? Read.

Searching for the perfect spyware remover (3185)

A look at four highly regarded anti-spyware tools and their effectiveness. / 2004-07-28

For when you already have spyware and want it removed ASAP. A good starting point. Read.

Using SCP (3411)

Command line and GUI clients / 2004-03-14

FTP may no longer be suitable for your file transferring needs. Here's the basics to SCP and where you can find some nifty GUI clients. Read.

Review: Jens of Sweden MP-110 (2580)

Just a review / 2004-03-13

A short review of the Jens of Sweden MP110 mp3 player. Read.

Pour vous, Yaniv: rss_feed

On some mobile device? Try this.

vafrous.com: blog / articles / projects

©2008 vafrous.com, Mike Sklut / v0.4a / validate

\Va"frous\, a. [L. vafer.] Crafty; cunning; sly; as, vafrous tricks.