注册 登录
编程论坛 C# 论坛

这代码哪出错了,求大神看看

清波无雯 发布于 2014-09-07 11:16, 734 次点击
try
                {
                    conn = new OleDbConnection(myconn);
                    conn.Open();
                    cmd = new OleDbCommand("select * from Student_Login where Sno = '" + textUser.Text.Trim() + "'" + "'and Password='" + textPwd.Text.Trim() + "' ", conn);
                    read = cmd.ExecuteReader();
                    //该学生信息存在且密码正确
                    if (read.Read())
                    {
                        //进入学生界面
                        Form2 form2 = new Form2();
                        form2.Show();
                    }
                    else  //没有该学生的信息
                    {
                        MessageBox.Show("不存在该学生或密码不正确!");
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.ToString());
                }
                finally
                {
                        read.Close();
                        conn.Close();  //关闭数据库连接
                  
                }
只有本站会员才能查看附件,请 登录


[ 本帖最后由 清波无雯 于 2014-9-7 11:20 编辑 ]
4 回复
#2
邓士林2014-09-07 12:04
Sno = '" + textUser.Text.Trim() + "'" + "'and Password='" + textPwd.Text.Trim() + "'就是这句错了,textUser.Text.Trim()、textPwd.Text.Trim()获取的已经是字符串形式了。
只有本站会员才能查看附件,请 登录

#3
清波无雯2014-09-09 10:29
回复 2 楼 邓士林
恩,谢谢,那里是出错了,不过修改后还是有点问题,还得在Sno前面加上Student才可以运行
#4
doomjust2014-10-15 23:46
貌似楼主应该跟我一样 在学C#面对象编程吧 。。
#5
chenhongwu2014-10-16 08:32
路过哈哈
1