C# 将datatable中的某列转换为数组

DataTable dt_Printquantity = new DataTable();
dt_Printquantity = ds.Tables[0];
  //将SampleNum列转数组
              
 //1:查询指定字段  string[] arraySampleNum = { "1"};
 int[] arraySampleNum = dt_Printquantity.AsEnumerable().Select(d => d.Field<int>("SampleNum")).ToArray();
 //2:转成string类型 并用逗号隔开每个值  
string
myStringOutput = String.Join(",", arraySampleNum.Select(p => p.ToString()).ToArray());
ViewBag.SampleNum = myStringOutput;

 

posted @ 2024-01-24 16:23  3939!  阅读(332)  评论(0编辑  收藏  举报