因为后续要用该数组进行运算,所以必须要传递到数组中
跪求 ORZ
6 个解决方案
#1
遍历数据集吧,或者你用linq去处理
#2
能详细点么?最好给个例子之类的,我不是太懂
#3
DataTable dt = ds.Tables[0];
float[] a = dt.AsEnumerable().Select(d => d.Field<float>("字段")).ToArray();
#4
要是多维数组呢?
#5
循环赋值不行吗
#6
楼主用这个类
public List<T> GetList<T>(DataTable table)
{
List<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
if (!value.ToString().Equals(""))
{
pro.SetValue(t, value, null);
}
}
}
list.Add(t);
}
return list.Count == 0 ? null : list;
}
然后遍历dataset里的datatable,每个表都转换成list,再转换成数组就ok了
public List<T> GetList<T>(DataTable table)
{
List<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
if (!value.ToString().Equals(""))
{
pro.SetValue(t, value, null);
}
}
}
list.Add(t);
}
return list.Count == 0 ? null : list;
}
然后遍历dataset里的datatable,每个表都转换成list,再转换成数组就ok了
#1
遍历数据集吧,或者你用linq去处理
#2
能详细点么?最好给个例子之类的,我不是太懂
#3
DataTable dt = ds.Tables[0];
float[] a = dt.AsEnumerable().Select(d => d.Field<float>("字段")).ToArray();
#4
要是多维数组呢?
#5
循环赋值不行吗
#6
楼主用这个类
public List<T> GetList<T>(DataTable table)
{
List<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
if (!value.ToString().Equals(""))
{
pro.SetValue(t, value, null);
}
}
}
list.Add(t);
}
return list.Count == 0 ? null : list;
}
然后遍历dataset里的datatable,每个表都转换成list,再转换成数组就ok了
public List<T> GetList<T>(DataTable table)
{
List<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
if (!value.ToString().Equals(""))
{
pro.SetValue(t, value, null);
}
}
}
list.Add(t);
}
return list.Count == 0 ? null : list;
}
然后遍历dataset里的datatable,每个表都转换成list,再转换成数组就ok了