1. Download and install MySQL Connector ODBC at http://dev.mysql.com/downloads/connector/odbc/5.1.html
2. Create a new Windows Application in C# express
3. Add the System.Data.Odbc namespace
4. Add a DataGridView
5. Use the following code to fill the DataGridView
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDatabase; User=root;Password=;Option=3;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("Select * from test",cn);
OdbcDataAdapter ad = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt;
*******************************************************************************
The code should look like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDatabase; User=root;Password=;Option=3;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("Select * from test",cn);
OdbcDataAdapter ad = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
2. Create a new Windows Application in C# express
3. Add the System.Data.Odbc namespace
4. Add a DataGridView
5. Use the following code to fill the DataGridView
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDatabase; User=root;Password=;Option=3;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("Select * from test",cn);
OdbcDataAdapter ad = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt;
*******************************************************************************
The code should look like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDatabase; User=root;Password=;Option=3;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("Select * from test",cn);
OdbcDataAdapter ad = new OdbcDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
Comments
http://www.latestbuzz2008.blogspot.com
htt://www.michelbolo.blogspot.com
http://ourlife143.blogspot.com
http://michel1432008.blogspot.com
http://cplus.about.com/od/howtodothingsinc/ss/mysqlnet.htm