Adding rows to dataset

后端 未结 3 457
余生分开走
余生分开走 2021-02-05 04:55

How can I create a DataSet that is manually filled? ie. fill through the code or by user input. I want to know the required steps if I need to create a DataTa

相关标签:
3条回答
  • 2021-02-05 05:08
     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);
    
    0 讨论(0)
  • 2021-02-05 05:13

    To add rows to existing DataTable in Dataset:

    DataRow drPartMtl = DSPartMtl.Tables[0].NewRow();
    drPartMtl["Group"] = "Group";
    drPartMtl["BOMPart"] = "BOMPart";
    DSPartMtl.Tables[0].Rows.Add(drPartMtl);
    
    0 讨论(0)
  • 2021-02-05 05:26
    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"]));    
    }
    
    0 讨论(0)
提交回复
热议问题