所以我想从数据库中创建一个文本(如日志文件)。每个文本代表一个用户的记录。显然,根据数据库,每条记录都有不同的名称。我想知道在创建文本文件时如何将字符串变量放在 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();
}