Hi all,

I would like to learn how I can read a MySQL table and move the records to an Excel file. While replying, please consider that I am at the very beginning of c# and write everything "Idiot proof"

Thanks
telmessos

Well to read your MySql database you can use the MySQL Connector-Net

here's a short example but you should read the MySql.Data.chm file for more info

MySqlConnection conn = new MySqlConnection("server=localhost;uid=csharp;pwd=csharp;database=csharptest;charset=utf8");
conn.Open();
cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM someTable";
MySqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
	Debug.WriteLine(reader.GetValue(0));
}

reader.Close();

conn.Close();

Hope it will help you.......:)

Edited 6 Years Ago by avirag: n/a

Thanks for the code. I will try it with this.

Well to read your MySql database you can use the MySQL Connector-Net

here's a short example but you should read the MySql.Data.chm file for more info

MySqlConnection conn = new MySqlConnection("server=localhost;uid=csharp;pwd=csharp;database=csharptest;charset=utf8");
conn.Open();
cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM someTable";
MySqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
	Debug.WriteLine(reader.GetValue(0));
}

reader.Close();

conn.Close();

Hope it will help you.......:)

I made the connection with ODBC because I had many problems with the other connection type and noone really helped me. I need to learn how to read data with an ODBC connection. Could not find any information. Please help

This article has been dead for over six months. Start a new discussion instead.