// 判断总分的优良等级
SqlConnection con3 = new SqlConnection("Server=.;database=QINXINJITUAN;uid=sa;pwd=12345;");
SqlDataReader dr1 = null;
con3.Open();
string score = "select details from FM_HUIZONG where item='score'";
SqlCommand cmd10 = new SqlCommand(score, con3);
dr1 = cmd10.ExecuteReader();
while (dr1.Read())
{
int s = Convert.ToInt32(dr1[0]);
if (s >= 90)
{
string score1 = "update FM_HUIZONG set DPT='优秀'where item='score'";
SqlCommand cmd11 = new SqlCommand(score1, con3);
cmd11.ExecuteNonQuery();
}
if (s >= 75 && s < 90)
{
string score2 = "update FM_HUIZONG set DPT='良好'where item='score'";
SqlCommand cmd12 = new SqlCommand(score2, con3);
cmd12.ExecuteNonQuery();
}
if (s >= 60 && s < 75)
{
string score3 = "update FM_HUIZONG set DPT='中等'where item='score'";
SqlCommand cmd13 = new SqlCommand(score3, con3);
cmd13.ExecuteNonQuery();
}
if (s >= 45 && s < 60)
{
string score4 = "update FM_HUIZONG set DPT='较差'where item='score'";
SqlCommand cmd14 = new SqlCommand(score4, con3);
cmd14.ExecuteNonQuery();
}
if (s <= 45)
{
string score5 = "update FM_HUIZONG set DPT='很差'where item='score'";
SqlCommand cmd15 = new SqlCommand(score5, con3);
cmd15.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
这段代码提示“已有打开的与此命令相关联的 DataReader,必须首先将它关闭”。可是我不知道怎么修改,是不是之前的代码也要贴上来。谢谢大家了
SqlConnection con3 = new SqlConnection("Server=.;database=QINXINJITUAN;uid=sa;pwd=12345;");
SqlDataReader dr1 = null;
con3.Open();
string score = "select details from FM_HUIZONG where item='score'";
SqlCommand cmd10 = new SqlCommand(score, con3);
dr1 = cmd10.ExecuteReader();
while (dr1.Read())
{
int s = Convert.ToInt32(dr1[0]);
if (s >= 90)
{
string score1 = "update FM_HUIZONG set DPT='优秀'where item='score'";
SqlCommand cmd11 = new SqlCommand(score1, con3);
cmd11.ExecuteNonQuery();
}
if (s >= 75 && s < 90)
{
string score2 = "update FM_HUIZONG set DPT='良好'where item='score'";
SqlCommand cmd12 = new SqlCommand(score2, con3);
cmd12.ExecuteNonQuery();
}
if (s >= 60 && s < 75)
{
string score3 = "update FM_HUIZONG set DPT='中等'where item='score'";
SqlCommand cmd13 = new SqlCommand(score3, con3);
cmd13.ExecuteNonQuery();
}
if (s >= 45 && s < 60)
{
string score4 = "update FM_HUIZONG set DPT='较差'where item='score'";
SqlCommand cmd14 = new SqlCommand(score4, con3);
cmd14.ExecuteNonQuery();
}
if (s <= 45)
{
string score5 = "update FM_HUIZONG set DPT='很差'where item='score'";
SqlCommand cmd15 = new SqlCommand(score5, con3);
cmd15.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
这段代码提示“已有打开的与此命令相关联的 DataReader,必须首先将它关闭”。可是我不知道怎么修改,是不是之前的代码也要贴上来。谢谢大家了
解决方案 »
- LINQ里的日期字符串比较
- C# webbroswer屏蔽flash右击,哪位老大帮忙解决下,谢谢
- DevExpress GridControl 问题
- winform程序“如何强制用户下线”(待解)
- C# 如何制作类似音速启动的列表?(鼠标可以多选)
- C#备份Oracle数据库
- 关于参数的问题
- 用command添加参数更新sql数据库时,用的sql语句可不可以包含子查询?急!!
- 可悲啊!我都快吐血了!!!大家快来!
- Gridview 导出的html格式文件如何直拉转成标准的excel文件?
- asp.net前台OnClientClick的使用问题。急。在线等待。。。
- DotNetBar的DatagridviewX控件
我觉得楼主应该专门为打开连接定义一个GetConnection()的函数,然后没调用一个dataReader之前都要调用此函数打开一个新的数据库连接