943,152 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 578
  • C# RSS
Jan 5th, 2010
0

Migrate records from MySQL to Excel with c#

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
telmessos is offline Offline
5 posts
since Jan 2010
Jan 6th, 2010
0
Re: Migrate records from MySQL to Excel with c#
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
C# Syntax (Toggle Plain Text)
  1. MySqlConnection conn = new MySqlConnection("server=localhost;uid=csharp;pwd=csharp;database=csharptest;charset=utf8");
  2. conn.Open();
  3. cmd = new MySqlCommand();
  4. cmd.Connection = conn;
  5. cmd.CommandText = "SELECT * FROM someTable";
  6. MySqlDataReader reader = cmd.ExecuteReader();
  7.  
  8. while (reader.Read())
  9. {
  10. Debug.WriteLine(reader.GetValue(0));
  11. }
  12.  
  13. reader.Close();
  14.  
  15. conn.Close();

Hope it will help you.......
Last edited by avirag; Jan 6th, 2010 at 4:05 am.
Reputation Points: 31
Solved Threads: 36
Posting Whiz
avirag is offline Offline
312 posts
since Jun 2009
Jan 6th, 2010
0
Re: Migrate records from MySQL to Excel with c#
Thanks for the code. I will try it with this.

Click to Expand / Collapse  Quote originally posted by avirag ...
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
C# Syntax (Toggle Plain Text)
  1. MySqlConnection conn = new MySqlConnection("server=localhost;uid=csharp;pwd=csharp;database=csharptest;charset=utf8");
  2. conn.Open();
  3. cmd = new MySqlCommand();
  4. cmd.Connection = conn;
  5. cmd.CommandText = "SELECT * FROM someTable";
  6. MySqlDataReader reader = cmd.ExecuteReader();
  7.  
  8. while (reader.Read())
  9. {
  10. Debug.WriteLine(reader.GetValue(0));
  11. }
  12.  
  13. reader.Close();
  14.  
  15. conn.Close();

Hope it will help you.......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
telmessos is offline Offline
5 posts
since Jan 2010
Jan 7th, 2010
0
Re: Migrate records from MySQL to Excel with c#
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
telmessos is offline Offline
5 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: problem of accessing a Form element
Next Thread in C# Forum Timeline: Gettiing the line number of a string





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC