none
How can i import a table in mysql? RRS feed

  • Question

  • Hello all i got a little problem i dont know how to import a table (account.sql) from my directory (C:/MyDocument/DATA/) to my database (JOB) in MySql using MySQL Connector Net 5.0.7.

    I need to import some new tables i got in (.sql) format.

    Thx in advance.
    Friday, August 17, 2007 6:20 PM

Answers

  • Consider the following snippet as a conceptual example... It's up to you to repair the syntax errors...

    Code Snippet

    using(TextReader reader = new TextReader(File.Open(@"c:\MyDocument\Data\something.sql"))))
    using (MySqlConnection conn = new MysqlConnection(" connectionstring "))
    {
     MySqlCommand cmd = conn.CreateCommand();
     foreach(string line in textReader.ReadLine())
     {
      cmd.CommandText = line;
      cmd.ExecuteScalar();
     }
    }



    (Anyway, i would probably use the mysql.exe commandline tool instead...)
    Friday, August 17, 2007 7:15 PM

All replies

  • Consider the following snippet as a conceptual example... It's up to you to repair the syntax errors...

    Code Snippet

    using(TextReader reader = new TextReader(File.Open(@"c:\MyDocument\Data\something.sql"))))
    using (MySqlConnection conn = new MysqlConnection(" connectionstring "))
    {
     MySqlCommand cmd = conn.CreateCommand();
     foreach(string line in textReader.ReadLine())
     {
      cmd.CommandText = line;
      cmd.ExecuteScalar();
     }
    }



    (Anyway, i would probably use the mysql.exe commandline tool instead...)
    Friday, August 17, 2007 7:15 PM
  • thx alot....but this will upload a new table? or it will write the data to that existing table?
    Friday, August 17, 2007 7:59 PM
  • that depends on the commands in your file...
    Friday, August 17, 2007 8:01 PM
  • OK i get it thx alot.
    Friday, August 17, 2007 8:06 PM