求各位大神帮助,阅读器关闭时尝试调用 Read 无效。

weixin_38407556 2017-05-22 01:40:48
private void button1_Click(object sender, EventArgs e)
{
String user = stusno.Text.ToString();
String pwd = stupwd.Text.ToString();
SqlConnection con = new SqlConnection(sqlconn);
con.ConnectionString = @"server=DESKTOP-JGMS3CE\SQLEXPRESS;database=SMS;uid=sa;pwd="*********";
con.Open();
SqlCommand com = new SqlCommand("select * from Manage",con);
SqlDataReader read = com.ExecuteReader();
while(read.Read()){ ///////就是这一行报错
if(user==null||pwd==null){
MessageBox.Show("请输入用户名或密码");
break;
}
else if(user == read[0].ToString() && pwd == read[1].ToString())
{

Students getsl = new Students();
getsl.ShowDialog();


return;
}
read.Close();
con.Close();
...全文
166 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
本人QQ-554433626 2017-05-22
  • 打赏
  • 举报
回复
把 read.Close();和con.Close();放在while()外部
exception92 2017-05-22
  • 打赏
  • 举报
回复
如果 if,else if 中的条件都不满足 就会 执行read.close。 应该把close 放到 while 循环外边。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧