using System;
using System.Data;
namespace SaveDatasetAsXML
{
static class Program
{
static void Main(string[] args)
{
/* Tạo bảng Student*/
var tableStudent = new DataTable("Students");
tableStudent.Columns.Add("StuID", typeof(int));
tableStudent.Columns.Add("FirstName", typeof(string));
tableStudent.Columns.Add("LastName", typeof(string));
tableStudent.Columns.Add("BirthDay", typeof(DateTime));
tableStudent.PrimaryKey = new[] { tableStudent.Columns[0] }; // Thiết lập khóa
/* Nhập dữ liệu*/
tableStudent.Rows.Add(new object[] { 1, "Tuan", "Le Minh", "26/06/1999" });
tableStudent.Rows.Add(new object[] { 2, "Yen", "Nguyen Hai", "05/09/2000" });
tableStudent.Rows.Add(new object[] { 3, "Toan", "Pham Khanh", "05/07/1998" });
tableStudent.Rows.Add(new object[] { 4, "Binh", "Hoang Cong", "05/07/1999" });
tableStudent.Rows.Add(new object[] { 5, "Tung", "Le khanh", "04/06/1997" });
tableStudent.AcceptChanges();
/*Thêm bảng vừa tạo vào dataset*/
var dataset1 = new DataSet("DataSetName");
dataset1.Tables.Add(tableStudent);
/* Xuất dữ liệu ra file XML*/
dataset1.WriteXml("TenFile.xml");
Console.ReadKey();
}
}
}