![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
vs2010 在服务器资源管理器里面已经连接好了数据库,但调试过程中ExecuteReader 当前状态为关闭。。特急
源代码:conn=newSqlConnection(Properties.Settings.Default.选课管理系统ConnectionString);conn.Op...
源代码:
conn = new SqlConnection(Properties.Settings.Default.选课管理系统ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
SqlCommand cod = conn.CreateCommand();
if (radioButton1.Checked)
{
cmd.CommandText = "select * from student where sno='" + textBox1.Text + "'and spassword='" + textBox2.Text + "'";
SqlDataReader drr = cmd.ExecuteReader();
drr.Read();
if (drr.HasRows == false)
{
MessageBox.Show("密码或用户名有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
drr.Close();
textBox1.Text = "";
textBox2.Text = "";
return; 展开
conn = new SqlConnection(Properties.Settings.Default.选课管理系统ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
SqlCommand cod = conn.CreateCommand();
if (radioButton1.Checked)
{
cmd.CommandText = "select * from student where sno='" + textBox1.Text + "'and spassword='" + textBox2.Text + "'";
SqlDataReader drr = cmd.ExecuteReader();
drr.Read();
if (drr.HasRows == false)
{
MessageBox.Show("密码或用户名有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
drr.Close();
textBox1.Text = "";
textBox2.Text = "";
return; 展开
展开全部
切切要记住,使用SqlDataReader之前一定要打开数据搏模库连接,因为执行一次SqlDataReader访问后,“数据稿银余记录指针”(其实没有,但这样说你会明白些)就会走到文件键滚末尾。所以会出现文件关闭的状态。
![](https://ecmc.bdimg.com/public03/b4cb859ca634443212c22993b0c87088.png)
2024-10-28 广告
Altair HyperWorks软件授权是优菁科技(上海)有限公司为客户提供的重要服务之一。我们确保每位客户都能合法、安全地使用HyperWorks这一先进的CAE(计算机辅助工程)平台。通过与Altair公司的紧密合作,我们为客户提供正...
点击进入详情页
本回答由名片提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询