C# CSV 导出
static void Main(String[] args){Console.WriteLine("--------");string myconn = "Database='test';Data Source=localhost;User ID=root;Password=123456;CharSet=utf8;";//需要執行的SQL語句string mysql = "SELECT * from users";//創建數據庫連接MySqlConnection myconnection = new MySqlConnection(myconn);myconnection.Open();//創建MySqlCommand對象MySqlCommand mycommand = new MySqlCommand(mysql, myconnection);//通過MySqlCommand的ExecuteReader()方法構造DataReader對象MySqlDataReader myreader = mycommand.ExecuteReader();//int size = 1024;//int sizeCnt = (int)Math.Ceiling((double)dataGrid.RowCount / (double)2000);StreamWriter write = new StreamWriter("F:\\test.csv", false, Encoding.Default, 1024 * 4);write.Write("ID" + "," + "user_name" + "," +"user_passwd");write.WriteLine();while (myreader.Read()){string Tem = myreader.GetInt32(0) + "," + myreader.GetString(1) + "," + myreader.GetString(2);write.WriteLine(Tem);}write.Flush();write.Close();myreader.Close();myconnection.Close();}
?
總結
- 上一篇: CentOS远程硬盘重装技术之我见
- 下一篇: Ubuntu下搭建sun-jdk和Mav