首次发表,不太会写,那点干货上个分,废话不多说,不懂多看 ContractedBlock.gif ExpandedBlockStart.gif
 1 public void Publist() 2 { 3  ResultListData resultData = new ResultListData(); 4  BLL.basic_project bllspro = new BLL.basic_project(); 5  6  int pageIndex = string.IsNullOrEmpty(context.Request["page"]) ? 1 : Convert.ToInt32(context.Request["page"]); 7  int pageSize = string.IsNullOrEmpty(context.Request["limit"]) ? 10 : Convert.ToInt32(context.Request["limit"]); 8  9  var strWhere = " is_del=0";10  DataSet ds = bllspro.GetListByPage(strWhere, "", pageIndex * pageSize - pageSize + 1, pageIndex * pageSize);11 12  DataTable table = new DataTable();      创建DataTable13 14  table.Columns.Add("autoid", typeof(string));  为DataTable添加列15  table.Columns.Add("pub_id", typeof(string)); //typeof(string)为数据类型16  table.Columns.Add("pub_name", typeof(string));17  table.Columns.Add("pub_version", typeof(string));18  table.Columns.Add("pub_data", typeof(string));19  table.Columns.Add("pub_state", typeof(string));20 21  foreach (DataRow dr in ds.Tables[0].Rows)22  {23   DataRow row = table.NewRow();24   row[0] = dr["autoid"];25   row[1] = dr["project_id"];26   row[2] = dr["project_name"];27   row[3] = "2020.7.1.1.0";//版本这里随便加的数据28   row[4] = dr["add_time"];//日期29   row[5] = dr["project_state"];30   table.Rows.Add(row);31  }32 33  ds.Reset();    //清除DataSet 34  ds.Tables.Add(table); //将表添加到DataSet中35  var count = ds.Tables[0].Rows.Count; //获取行数36  37  resultData.code = 0;38  resultData.msg = "获取数据成功!";39  resultData.data = table;40  resultData.count = count;41  var json = JsonHelper.ToJsonTime(resultData);42  context.Response.Write(json);43 }
View Code

 

将数据库查询出DataSet类数据表变成新的一张表
文章转载:http://www.shaoqun.com/a/463652.html