データベースからテキスト(ログファイルなど)を作成したいと思います。各テキストは、ユーザーのレコードを表します。明らかに、各レコードはデータベースに応じて異なる名前を持っています。そして、テキストファイルを作成するときに、文字列変数を doubleqoute 内に配置する方法を考えています。
public static void createLog()
{
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "SERVER=localhost;DATABASE=s_project;UID=root;PASSWORD='';";SELECT
con.Open();
MySqlCommand thiscommand = con.CreateCommand();
thiscommand.CommandText = "SELECT user_name FROM user_info";
MySqlDataReader read = thiscommand.ExecuteReader();
while (read.Read())
{
string user_name;
user_name = read.GetString("user_name");
StreamWriter SW;
SW = File.CreateText("c:\\MyTextFile.txt"); //what should I put instead of MyTextFile if I would like it to be the variable user_name?
}
con.Close();
}