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

Recommended Answers

All 3 Replies

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.......:)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.