CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Migrate records from MySQL to Excel with c#

    if you decide to use the mysql connector-net there's a chance I can guide otherwise you have to wait for someone else to help you
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  2. #17
    Join Date
    Jan 2007
    Posts
    28

    Re: Migrate records from MySQL to Excel with c#

    I changed it to mysql-connector-net I don't have the previous error but a new one when I copy and paste the first code you gave, I get the following errors:

    the name 'cmd' does not exist in the current context

  3. #18
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Migrate records from MySQL to Excel with c#

    Quote Originally Posted by telmessos View Post
    the name 'cmd' does not exist in the current context
    oops, sorry, I forgot to copy one more line last time, here's my test class again:
    Code:
    class MySqlTest
    {
    	public static void RunTest()
    	{
    		MySqlConnection conn = new MySqlConnection("server=localhost;uid=csharp;pwd=csharp;database=csharptest;charset=utf8");
    		conn.Open();
    		
    		MySqlCommand cmd = new MySqlCommand();
    		cmd.Connection = conn;
    		cmd.CommandText = "SELECT * FROM someTable";
    		MySqlDataReader reader = cmd.ExecuteReader();
    
    		while (reader.Read())
    		{
    			Debug.WriteLine(reader[0] + " -- " + reader[1]); // 0 and 1 because I've got two collumns in my test table
    		}
    
    		reader.Close();
    		conn.Close();
                           
                           reader.Dispose();
                           conn.Dispose();
    	}
    }
    this is only a sample so there is no try/catch and your app will crash if an error occurs
    Last edited by memeloo; January 7th, 2010 at 04:50 AM. Reason: I forgot to dispose agian
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  4. #19
    Join Date
    Jan 2007
    Posts
    28

    Re: Migrate records from MySQL to Excel with c#

    it seems to have no errors given. If I put the connection code on the form load section. Is it global? And how do I close connection at the end of the program? (asking too much )

  5. #20
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Migrate records from MySQL to Excel with c#

    Quote Originally Posted by telmessos View Post
    it seems to have no errors given. If I put the connection code on the form load section. Is it global?
    yes, if you make it a filed it will be class-wide accessible

    Quote Originally Posted by telmessos View Post
    And how do I close connection at the end of the program? (asking too much )
    do this:
    Code:
    reader.Close();
    conn.Close();
    
    reader.Dispose();
    conn.Dispose();
    Last edited by memeloo; January 7th, 2010 at 04:50 AM.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #21
    Join Date
    Jan 2007
    Posts
    28

    Re: Migrate records from MySQL to Excel with c#

    thanks

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured