在C# 里面用sqldataread执行判断数据库是否有相同记录,如果没有,就插入需要写入的数据,然后退出IF,继续执行下面的语句,到这里没有任何问题。
但是IF语句如果判断有数据,就出现提示信息,然后退出IF,在执行下面的语句,这个时候,下面的SQL语句就提示超时,请问怎么解决。
//判断当前选择日期数据是否存在
string shuju = "select * from kouxi where riqi='"+dateTimePicker1.Text.ToString()+"'"; SqlCommand shuju1 = new SqlCommand(shuju, shujupanduan1); SqlDataReader shuju2 = shuju1.ExecuteReader(); shuju2.Read(); if (shuju2.HasRows == false)
{ for (int i = 0; i < dt.Rows.Count; i++)
{ string cmd = "insert into kouxi(riqi,cusid,CurrentBalance) values "
+ "('" + dateTimePicker1.Text.ToString() + "','" + dt.Rows[i]["CusID"].ToString() + "','" + dt.Rows[i]["CurrentBalance"].ToString() + "')"; SqlCommand cmd1 = new SqlCommand(cmd, xc1);
cmd1.ExecuteNonQuery();
}
return;
}
//else
//{ // MessageBox.Show("已存在'"+dateTimePicker1.Text.ToString()+"'的数据,将以第一次获取的数据为标准计算","提示信息");
//}
string kouxiqt = "update kouxi "
+ "set salesname=b.salesname,cusjc=b.cusjc,cusname=b.cusname,xse_xy=b.MonSalesAmount1*b.drXYXS"
+ " from kouxi a left join jichushuju b on a.cusid=b.cusid"
+ " where a.riqi=b.riqi";
SqlCommand kouxiqt1 = new SqlCommand(kouxiqt,xc1);
kouxiqt1.ExecuteNonQuery();
最后一条语句就提示超时。
请问怎么解决。
但是IF语句如果判断有数据,就出现提示信息,然后退出IF,在执行下面的语句,这个时候,下面的SQL语句就提示超时,请问怎么解决。
//判断当前选择日期数据是否存在
string shuju = "select * from kouxi where riqi='"+dateTimePicker1.Text.ToString()+"'"; SqlCommand shuju1 = new SqlCommand(shuju, shujupanduan1); SqlDataReader shuju2 = shuju1.ExecuteReader(); shuju2.Read(); if (shuju2.HasRows == false)
{ for (int i = 0; i < dt.Rows.Count; i++)
{ string cmd = "insert into kouxi(riqi,cusid,CurrentBalance) values "
+ "('" + dateTimePicker1.Text.ToString() + "','" + dt.Rows[i]["CusID"].ToString() + "','" + dt.Rows[i]["CurrentBalance"].ToString() + "')"; SqlCommand cmd1 = new SqlCommand(cmd, xc1);
cmd1.ExecuteNonQuery();
}
return;
}
//else
//{ // MessageBox.Show("已存在'"+dateTimePicker1.Text.ToString()+"'的数据,将以第一次获取的数据为标准计算","提示信息");
//}
string kouxiqt = "update kouxi "
+ "set salesname=b.salesname,cusjc=b.cusjc,cusname=b.cusname,xse_xy=b.MonSalesAmount1*b.drXYXS"
+ " from kouxi a left join jichushuju b on a.cusid=b.cusid"
+ " where a.riqi=b.riqi";
SqlCommand kouxiqt1 = new SqlCommand(kouxiqt,xc1);
kouxiqt1.ExecuteNonQuery();
最后一条语句就提示超时。
请问怎么解决。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货