C#中关于大数据库的查询遍历问题
一个数据表有50行X576列。里头有27种数值(字符串型)。怎样较快地遍历数据表并把27种数据存到一个数组里头!
我用了两个for加一个switch,不过效率不高!【用了20分钟也没处理完,是不是和数值类型有关?!!】谢谢!
代码如下:
public int[] FiveMinutes(string str)
{
DB db = new DB();
int[] Channel = new int[27];
for (int i = 0; i <= db.reDt(str).Rows.Count - 1; i++)
{
for (int j = 0; j < 85; j++)
{
switch (db.reDt(str).Rows[i][j].ToString())
{
case "CCTV-1": Channel[0]++; break;
case "CCTV-2": Channel[1]++; break;
case "CCTV-3": Channel[2]++; break;
case "CCTV-4": Channel[3]++; break;
case "CCTV-5": Channel[4]++; break;
case "CCTV-6": Channel[5]++; break;
case "CCTV-7": Channel[6]++; break;
case "CCTV-8": Channel[7]++; break;
case "CCTV-9": Channel[8]++; break;
case "浙江卫视": Channel[9]++; break;
case "东方卫视": Channel[10]++; break;
case "安徽卫视": Channel[11]++; break;
case "北京卫视": Channel[12]++; break;
case "辽宁卫视": Channel[13]++; break;
case "山东卫视": Channel[14]++; break;
case "天津卫视": Channel[15]++; break;
case "宁夏卫视": Channel[16]++; break;
case "河南卫视": Channel[17]++; break;
case "湖北卫视": Channel[18]++; break;
case "四川卫视": Channel[19]++; break;
case "江西卫视": Channel[20]++; break;
case "贵州卫视": Channel[21]++; break;
case "广东卫视": Channel[22]++; break;
case "吉林卫视": Channel[23]++; break;
case "河北卫视": Channel[24]++; break;
case "重庆卫视": Channel[25]++; break;
case "广西卫视": Channel[26]++; break;
default: break;
}
}
}
for (int k = 0; k < 27; k++)
{
Channel[k] = Channel[k] * 5;
}
return Channel;
}
public DataTable reDt(string cmdstr)
{
SqlConnection con = GetCon();
SqlDataAdapter da = new SqlDataAdapter(cmdstr, con);
DataSet ds=new DataSet();
da.Fill(ds);
return (ds.Tables[0]);
}
哪里出问题了,求大神帮忙 我知道。
DB db = new DB();
int[] Channel = new int[27];
DataTable dt=db.reDt(str);
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
for (int j = 0; j < 85; j++)
{
switch (dt.Rows[i][j].ToString())
{
我是叫你改成这样试试