开发者

How to create Insert script using c#

开发者 https://www.devze.com 2022-12-29 16:07 出处:网络
From my c# code behind, i pass a query to mysql databa开发者_开发技巧se and get the data in a DataTable.

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 );
0

精彩评论

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