// 判断总分的优良等级
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,必须首先将它关闭”。可是我不知道怎么修改,是不是之前的代码也要贴上来。谢谢大家了
解决方案 »
- 连接数据库为什么抛出异常
- 求助 后台发送sendkeys
- 注释里插入当前日期,为以后察看
- 请教大家一个简单的问题
- 100分求助,Enterprise Library 5.0记录文本日志,为何重复记录至defaultCategory?
- 怎样使用C#进行 NTLM域认证???类似winhttp的方式。
- 关于VS2008
- C#如何把一个int数据转化成网络字节序(以二字节保存)
- DataSet里面可不可以定义字段长度?
- 请求高手解答:在Windows Service中如何进行异步监听MSMQ消息?
- asp.net前台OnClientClick的使用问题。急。在线等待。。。
- DotNetBar的DatagridviewX控件
我觉得楼主应该专门为打开连接定义一个GetConnection()的函数,然后没调用一个dataReader之前都要调用此函数打开一个新的数据库连接