一:DataSet
DataSet ds = new DataSet();//创建DataSet
DataTable dt = new DataTable();//创建一个DataTalbe dt.Columns.Add(new DataColumn("id", typeof(int)));//为dt_dry表内建立Column
dt.Columns.Add(new DataColumn("SQBM", typeof(string)));
dt.Columns.Add(new DataColumn("UNAME", typeof(string))); for (int i = ; i < ods.Tables[].Rows.Count; i++)
{
DataRow dr = dt.NewRow(); dr["id"] = i + ;
dr["SQBM"] = ods.Tables[].Rows[i]["SQBM"].ToString();
dr["UNAME"] = username;
if (i == ods.Tables[].Rows.Count - )
{
dt.Rows.Add(dr);
ds.Tables.Add(dt);
}
else
dt.Rows.Add(dr);
}
}
二:DataTable
DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("id", typeof(string)));
dt.Columns.Add(new DataColumn("UName", typeof(string))); for (Int i = ; i < ds.Table[].Rows.count; i++)
7 {
DataRow dr = dt.NewRow();
dr["id"] = ds.Table[].Rows[i]["User_ID"].tostring();
dr["UName"] = ds.Table[].Rows[i]["strUName"].tostring();
dt.Rows.Add(dr); }