开发者

Better way to download mysql table using C#?

I currently use the code below but its not uncommon for it to throw an "tried to read past the stream" error once the mysql table has reached over 20 thousand entries.

MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            connection.Open();
            command.CommandText = "SELECT * FROM mytable";
            MySqlDataReader result = command.ExecuteReader();
            string thisrow = "";
                if (result != null)
                    while (result.Read())
                    {

                        for (int i = 0; i < result.FieldCount; i++)
                            thisrow += result.GetValue(i).ToString() + ",";
                        pass = Regex.Replace(thisrow, @"\W*", "");
                        if (!hshTable.ContainsKey(pass)) hshTable.Add(pass, pass);
                    }
            connection.Close();

is there a mysql command lik开发者_开发问答e LOAD DATA LOCAL INFILE 'C:/mysqltable.txt' INTO TABLE mytable FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";

but instead of loading a file to the database it downloads the table instead? or is there a better way of doing this without using extra applications and/or software?


The .NET connector uses BulkLoader as a wrapper for the LOAD DATA INFILE command.

You can find the details here.

Be warned though - the bulkloader has only vague documentation and I found that sometimes it will fail with larger files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜