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;