发布时间:2023-05-12 11:30
1、创建DataSet
2、创建DataTable
3、将DataTable加入到DataSet
4、创建列
5、创建行、并加入到DataTable
以下是Demo 代码
DataSet ds = new();
DataTable dt = new DataTable("MyTable");//创建一个名为MyTable的DataTalbe
ds.Tables.Add(dt);
dt.Columns.Add(new DataColumn("BillCode", typeof(string)));
dt.Columns.Add(new DataColumn("OrderNo", typeof(string)));
dt.Columns.Add(new DataColumn("SellerName", typeof(string)));
dt.Columns.Add(new DataColumn("GoodsName", typeof(string)));
dt.Columns.Add(new DataColumn("Pcs", typeof(Int32)));
dt.Columns.Add(new DataColumn("ClaimReason", typeof(string)));
dt.Columns.Add(new DataColumn("Weight", typeof(float)));
dt.Columns.Add(new DataColumn("Price", typeof(float)));
dt.Columns.Add(new DataColumn("Amount", typeof(float)));
dt.Columns.Add(new DataColumn("Remark", typeof(string)));
dt.Columns.Add(new DataColumn("ApplyTime", typeof(string)));
dt.Columns.Add(new DataColumn("TakePartsDate", typeof(string)));
foreach(TData data in MainDataList)
{
DataRow dr = dt.NewRow();
dr["BillCode"] = data.BillCode;
dr["OrderNo"] = data.OrderNo;
dr["SellerName"] = data.SellerName;
dr["GoodsName"] = data.GoodsName;
dr["Pcs"] = data.Pcs;
dr["ClaimReason"] = data.ClaimReason;
dr["Weight"] = data.Weight;
dr["Price"] = data.Price;
dr["Amount"] = data.Amount;
dr["Remark"] = data.Remark;
dr["ApplyTime"] = data.ApplyTime;
dr["TakePartsDate"] = data.TakePartsDate;
dt.Rows.Add(dr);
}