如何创建DataSet
手动填充的?即.填写代码或用户输入.我想知道所需的步骤,如果我需要创建一个DataTable
或DataRow
第一个,我真的不知道填写的步骤DataSet
.
DataSet ds = new DataSet(); DataTable dt = new DataTable("MyTable"); dt.Columns.Add(new DataColumn("id",typeof(int))); dt.Columns.Add(new DataColumn("name", typeof(string))); DataRow dr = dt.NewRow(); dr["id"] = 123; dr["name"] = "John"; dt.Rows.Add(dr); ds.Tables.Add(dt);
DataSet myDataset = new DataSet(); DataTable customers = myDataset.Tables.Add("Customers"); customers.Columns.Add("Name"); customers.Columns.Add("Age"); customers.Rows.Add("Chris", "25"); //Get data DataTable myCustomers = myDataset.Tables["Customers"]; DataRow currentRow = null; for (int i = 0; i < myCustomers.Rows.Count; i++) { currentRow = myCustomers.Rows[i]; listBox1.Items.Add(string.Format("{0} is {1} YEARS OLD", currentRow["Name"], currentRow["Age"])); }