I want to export a table from a mysql database to a txt or csv file like the way you can in phpmyadmin . I currently use the code below but after the program has been running for a few hours it will throw an "tried to read past the stream" error.
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
connection.Open();
command.CommandText = "SELECT * FROM mytable";
MySqlDataReader result = command.ExecuteReader();
if (result != null)
while (result.Read())
{
string thisrow = "";
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 command like myquerystring = "LOAD DATA LOCAL INFILE 'C:/mysqltable.txt' INTO TABLE mytable FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
that instead of loading a file to the database it downloads the table instead?
ok I tried
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
connection.Open();
myquerystring = "SELECT * INTO OUTFILE 'E:/mysqldump.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM mytable";
command.CommandText = myquerystring;
command.ExecuteNonQuery();
but it keeps giving me a "Access denied for user 'admin'@'myip' (using password: YES)" error where myip is really my ip and not the servers even though the servers IP is specified in MyConString.