From my c# code behind, i pass a query to mysql databa开发者_开发技巧se and get the data in a DataTable. Now i want to use the data in data table to write the Insert query in a script file [.sql]
The objective of doing so is, whatever records i select from mysql, i should write that to a script file as backup. Thais why i need the insert statements.
How ? Or any other idea is appreciated.
Isn't that why they invented mysqldump?
This allows you to dump a table to as file, as a create statement + a bunch of insert statements.
EDIT: see also this article about Using mysqldump
If I understand you correctly, you're doing something like this
string sql = "INSERT sometable (a, b, c) SELECT 1, 2, 3";
DataLayer.Run( sql );
and you want to do something like this
System.IO.File.WriteAllText( "script.sql", sql );
Or, to log multiple statements,
System.IO.File.AppendAllText( "script.sql", sql + Environment.NewLine );
精彩评论