public static class Extensions { public static string ToCSV(this DataTable table) { var result = new StringBuilder(); for (int i = 0; i < table.Columns.Count; i++) { result.Append(table.Columns[i].ColumnName); result.Append(i == table.Columns.Count - 1 ? "\n" : ","); } foreach (DataRow row in table.Rows) { for (int i = 0; i < table.Columns.Count; i++) { result.Append(row[i].ToString()); result.Append(i == table.Columns.Count - 1 ? "\n" : ","); } } return result.ToString(); } }
public static void Main() { DataTable table = new DataTable(); table.Columns.Add("Name"); table.Columns.Add("Age"); table.Rows.Add("John Doe", "45"); table.Rows.Add("Jane Doe", "35"); table.Rows.Add("Jack Doe", "27"); var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(table.ToCSV()); MemoryStream stream = new MemoryStream(bytes); StreamReader reader = new StreamReader(stream); Console.WriteLine(reader.ReadToEnd()); }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง