private void ShowData()
{
Sex = getSex();
CityCode = getCityCode();
Conn = new SqlConnection(ConnStr);
try
{
if(this.radioButton1.Checked)
{
SqlDataAdapter adapter1 = new SqlDataAdapter();
adapter1.TableMappings.Add("Table","TVR_IDData");
Conn.Open();
if(CityCode=="")
{
sql = "select userid as ID,TelNumber as 手机号码,usex as 性别,uage as 年龄,";
sql += "convert(varchar,idenableddatetime,120) as 注册时间,onlineenabled as 是否在线,";
sql += "0 拨打次数,0 费用 from tvr_iddata where curstate=1 and usex="+Sex;
}
else
{
sql = "select userid as ID,TelNumber as 手机号码,usex as 性别,uage as 年龄,";
sql += "convert(varchar,idenableddatetime,120) as 注册时间,onlineenabled as 是否在线,";
sql += "0 拨打次数,0 费用 from tvr_iddata where curstate=1 and usex="+Sex+" and ";
sql += "(left(telnumber,7) in (select mobilecode from gr_mast_mobilearea where cityno="+CityCode+"))";
}
SqlCommand comm1 = new SqlCommand(sql,Conn);
comm1.CommandType = CommandType.Text;
adapter1.SelectCommand = comm1;
ds = new DataSet();
adapter1.Fill(ds);
foreach(DataRow dr in ds.Tables["tvr_iddata"].Rows)
{
string mobile = dr["手机号码"].ToString();
int fee = 0;
SqlDataAdapter adapter2 = new SqlDataAdapter();
adapter2.TableMappings.Add("Table","CTI_InBoundDetail");
sql = "select count(*) from CTI_InBoundDetail where Ani='"+mobile+"' and Dnis='"+this.radioButton1.Text+"'";
SqlCommand comm2 = new SqlCommand(sql,Conn);
comm2.CommandType = CommandType.Text;
adapter2.SelectCommand = comm2;
DataSet ds1 = new DataSet();
adapter2.Fill(ds1);
dr["拨打次数"] = ds1.Tables["CTI_InBoundDetail"].Rows[0][0]; SqlDataAdapter adapter3 = new SqlDataAdapter();
adapter3.TableMappings.Add("Table","Bill_Detail");
sql = "select Totalbill from Bill_Detail where Telnumber='"+mobile+"' and Talklen<>0";
SqlCommand comm3 = new SqlCommand(sql,Conn);
comm3.CommandType = CommandType.Text;
adapter3.SelectCommand = comm3;
DataSet ds2 = new DataSet();
adapter3.Fill(ds2);
foreach(DataRow dr1 in ds2.Tables["Bill_Detail"].Rows)
{
fee += Int32.Parse(dr1["Totalbill"].ToString());
}
dr["费用"] = fee;
}
//MessageBox.Show(sql);
}
if(this.radioButton2.Checked)
{
MessageBox.Show(this.radioButton2.Text);
}
this.dataGrid1.DataSource = ds.Tables["tvr_iddata"].DefaultView;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Conn.Close();
}
上面的程序处理大量数据[取一条两条也很慢]时我的程序就未响应了,请各位大虾帮我改改呀,急呀。
{
Sex = getSex();
CityCode = getCityCode();
Conn = new SqlConnection(ConnStr);
try
{
if(this.radioButton1.Checked)
{
SqlDataAdapter adapter1 = new SqlDataAdapter();
adapter1.TableMappings.Add("Table","TVR_IDData");
Conn.Open();
if(CityCode=="")
{
sql = "select userid as ID,TelNumber as 手机号码,usex as 性别,uage as 年龄,";
sql += "convert(varchar,idenableddatetime,120) as 注册时间,onlineenabled as 是否在线,";
sql += "0 拨打次数,0 费用 from tvr_iddata where curstate=1 and usex="+Sex;
}
else
{
sql = "select userid as ID,TelNumber as 手机号码,usex as 性别,uage as 年龄,";
sql += "convert(varchar,idenableddatetime,120) as 注册时间,onlineenabled as 是否在线,";
sql += "0 拨打次数,0 费用 from tvr_iddata where curstate=1 and usex="+Sex+" and ";
sql += "(left(telnumber,7) in (select mobilecode from gr_mast_mobilearea where cityno="+CityCode+"))";
}
SqlCommand comm1 = new SqlCommand(sql,Conn);
comm1.CommandType = CommandType.Text;
adapter1.SelectCommand = comm1;
ds = new DataSet();
adapter1.Fill(ds);
foreach(DataRow dr in ds.Tables["tvr_iddata"].Rows)
{
string mobile = dr["手机号码"].ToString();
int fee = 0;
SqlDataAdapter adapter2 = new SqlDataAdapter();
adapter2.TableMappings.Add("Table","CTI_InBoundDetail");
sql = "select count(*) from CTI_InBoundDetail where Ani='"+mobile+"' and Dnis='"+this.radioButton1.Text+"'";
SqlCommand comm2 = new SqlCommand(sql,Conn);
comm2.CommandType = CommandType.Text;
adapter2.SelectCommand = comm2;
DataSet ds1 = new DataSet();
adapter2.Fill(ds1);
dr["拨打次数"] = ds1.Tables["CTI_InBoundDetail"].Rows[0][0]; SqlDataAdapter adapter3 = new SqlDataAdapter();
adapter3.TableMappings.Add("Table","Bill_Detail");
sql = "select Totalbill from Bill_Detail where Telnumber='"+mobile+"' and Talklen<>0";
SqlCommand comm3 = new SqlCommand(sql,Conn);
comm3.CommandType = CommandType.Text;
adapter3.SelectCommand = comm3;
DataSet ds2 = new DataSet();
adapter3.Fill(ds2);
foreach(DataRow dr1 in ds2.Tables["Bill_Detail"].Rows)
{
fee += Int32.Parse(dr1["Totalbill"].ToString());
}
dr["费用"] = fee;
}
//MessageBox.Show(sql);
}
if(this.radioButton2.Checked)
{
MessageBox.Show(this.radioButton2.Text);
}
this.dataGrid1.DataSource = ds.Tables["tvr_iddata"].DefaultView;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Conn.Close();
}
上面的程序处理大量数据[取一条两条也很慢]时我的程序就未响应了,请各位大虾帮我改改呀,急呀。
解决方案 »
- C#如何做出和电脑自带计算器TextBox一样,请看:
- 有一个阿里88的面试题 第四题 我感觉是 死锁
- c#通过在textbox中输入内容在datagridview查询数据
- C#控件问题
- 要用Winform开发一个比赛用的记分牌,有个问题要请教一下大家
- winform 中 datagrid 数据填充
- [散分]Beginning C# Objects中文版--概念到代码--->>>要答案
- databale使用select查询后,如何重新绑定datatable所有数据?
- vs.net 2003有BUG?
- webgame serverpush 怎么实现啊
- 关于延时
- ComboBox和一字段绑定,当改变ComboBox下拉项时如何更新绑定的数据库?
用in的语句先优化。in的效率太低,想办法用其他关联的方式来实现。另外自己添加一些时间的判断来查看下哪句语句耗时最长。是.net的语句还是数据库执行的语句?
同时建议,不要在循环里面做读写数据库操作,效率太低,如果可能的话,一次性读出,然后再做关联处理。
ID,用户ID,手机号,性别,年龄,注册时间
1,12345,136000,女,23,2005-10-10B表(用户每次打入都会生成一条)
ID,手机号,费用
1,13600,10C表(用户只要打入了也会生成一条)
ID,手机号
1,136000我现在要求在DATAGRID中显示:
用户编号,手机号,性别,年龄,注册时间,打入次数,费用大家教如何做?
ID,用户ID,手机号,性别,年龄,注册时间
1,12345,136000,女,23,2005-10-10B表(用户每次打入都会生成一条)
ID,手机号,费用
1,13600,10C表(用户只要打入了也会生成一条)
ID,手机号
1,136000我现在要求在DATAGRID中显示:
用户编号,手机号,性别,年龄,注册时间,打入次数,费用这就是我的需求,现在问题是,我按我自己的思路实现的代码,运行太慢,还导至软件死掉。
SELECT telno, COUNT(*) AS times, SUM(fee) AS fee
FROM dbo.tel_zl
GROUP BY telno
在用A表与视图做关联查询
A,
(SELECT telno/UserID, COUNT(*) AS times, SUM(fee) AS fee
FROM B
GROUP BY telno) BB
where A.telno/UserID=BB.telno/UserID