DataRow[] rows = ds.Tables["db"].Select("tmp1<>'' and tmp2<>'' and tmp3<>''","");
foreach(datacolumn dc in ds.table[0].columns) { foreach(datarow dr in ds.table[0].rows) { if(有值) { count+=1; break;//跳出本次循环 } } }试试
select tmp1,tmp2,tmp3 from db where tmp1 is not null and tmp2 is not null and tmp3 is not null
ds.Tables[0].Columns.Count 就是列数
strint str ="select tmp1,tmp2,tmp3 from db" 。 DataSet ds = new DataSet(); mda.Fill(ds, "db");----------------------------- tmp1,tmp2,tmp3 你这里自己定义了三个列 啊! 怎么能控制列的显示啦?? 好像不能把1! 呵呵
select 有值的行数=count(*) from db where tmp1 is not null and tmp2 is not null and tmp3 is not nullselect 有值的列数= case when (select count(*) from db where tmp1 is null )>0 then 0 else 1 end + case when (select count(*) from db where tmp2 is null )>0 then 0 else 1 end + case when (select count(*) from db where tmp3 is null )>0 then 0 else 1 end
ds.Tables[0].Columns .Count 不就是列数了吗
列数?不太明白 比如 tmp1,tmp2,tmp3 1 , 1, 1 , 1, 1 , 1, 1 , ,是想得到 第1行:3列 第2行:3列 第3行:1列 第4行:1列如果是的话,统计一下就可以了foreach (DataRow dr in ds.Tables[0].Rows) { int count = 0; foreach (DataColumn dc in ds.Tables[0].Columns) { if (dr[dc].ToString() != string.Empty) { count++; } } ////count }
1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ] 其中i 代表第 i 行数, j 代表第 j 列数 3 DataSet.Tables[0].Columns.Count 取得表的总列数 4 DataSet.Tables[0].Rows.Count 取得表的总行数 5 DataSet.Tables[0].Columns[ i ].ToString() 取得表的 i 列名
{
foreach(datarow dr in ds.table[0].rows)
{
if(有值)
{
count+=1;
break;//跳出本次循环
}
}
}试试
where tmp1 is not null
and tmp2 is not null
and tmp3 is not null
就是列数
。
DataSet ds = new DataSet();
mda.Fill(ds, "db");-----------------------------
tmp1,tmp2,tmp3
你这里自己定义了三个列 啊!
怎么能控制列的显示啦??
好像不能把1!
呵呵
where tmp1 is not null and tmp2 is not null and tmp3 is not nullselect 有值的列数=
case when (select count(*) from db where tmp1 is null )>0 then 0 else 1 end
+
case when (select count(*) from db where tmp2 is null )>0 then 0 else 1 end
+
case when (select count(*) from db where tmp3 is null )>0 then 0 else 1 end
不就是列数了吗
比如
tmp1,tmp2,tmp3
1 , 1, 1
, 1, 1
, 1,
1 , ,是想得到
第1行:3列
第2行:3列
第3行:1列
第4行:1列如果是的话,统计一下就可以了foreach (DataRow dr in ds.Tables[0].Rows)
{
int count = 0;
foreach (DataColumn dc in ds.Tables[0].Columns)
{
if (dr[dc].ToString() != string.Empty)
{
count++;
}
}
////count
}
1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ] 其中i 代表第 i 行数, j 代表第 j 列数 3 DataSet.Tables[0].Columns.Count 取得表的总列数 4 DataSet.Tables[0].Rows.Count 取得表的总行数 5 DataSet.Tables[0].Columns[ i ].ToString() 取得表的 i 列名