Add data to the new dataset

How to add data to a new dataset

1. Create a new dataset

DataSet datas = new DataSet();

dataset can only add datatable to create a new datatable

2. Create a new datatable

DataTable datat = new DataTable();

Add datarow to datatable

3. Create a new datarow. Note that datatable (datat) cannot be used directly with new

DataRow row =datat.NewRow();

4. What to add to the datatable

datat.Columns.Add("ID");
datat.Columns.Add("UserID");
datat.Columns.Add("NewTitle");
datat.Columns.Add("MessageDateTime");

5. Officially add data to the datatable

for(i=0;i<n;i++)

{

row["ID"] = dds.Tables[0].Rows[i].ItemArray[0].ToString(); //dds is a dataset obtained directly from the database by other methods
 row["UserID"] = dds.Tables[0].Rows[i].ItemArray[1].ToString();
row["NewTitle"] = dds.Tables[0].Rows[i].ItemArray[4].ToString();
row ["MessageDateTime"] = dds.Tables[0].Rows[i].ItemArray[7].ToString();
datat.Rows.Add(row); //Add row elements to the table
row = datat.NewRow( ); //It is equivalent to emptying the row, otherwise the next loop cannot be assigned rows and cannot be repeatedly assigned

}

datas.Tables.Add(datat.Copy());

Since the ID is not unique, the data checked from the database are not in the same table, so they are spelled into the same table and then placed in the dataset

The main solution is that the content of the ID is not unique, such as the person receiving the message (classidentifier) ​​is not unique, the data is separated by ',' as follows

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325061426&siteId=291194637