首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

建立学生管理系统中运行这种异常如何解决

2013-08-01 
建立学生管理系统中运行这种错误怎么解决?[aligncenter][/align]这下面是代码:namespace 学管1{public pa

建立学生管理系统中运行这种错误怎么解决?
[align=center][/align建立学生管理系统中运行这种异常如何解决]
这下面是代码:


namespace 学管1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
             //设置连接字符串
            string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\专业软件\学管__1\学2数据库.mdb";
            DataSet dataset = new DataSet();      //创建数据集
            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();
            try
            {
                if (this.textBox1.Text == "") // 验证是否输入了用户姓名
                {
                    MessageBox.Show("用户名不能为空");
                    textBox1.Focus();
                    return;
                }

                if (this.textBox2.Text == "")// 验证是否输入了密码
                {
                    MessageBox.Show("请输入密码");
                    textBox2.Focus();
                    return;


                }
                if (radioButton1.Checked == true)
                {
                    string OleDb= string.Format("select count(*) from Users  where User_id='{0}' and User_password='{1}'and User_power='{2}'", this.textBox1.Text, this.textBox2.Text, 1);
                    OleDbCommand comm = new OleDbCommand(OleDb, conn); // 创建comm对象
                    int count = (int)comm.ExecuteScalar();//执行查询,并返回查询
                    if (count == 1)//判断是否存在这样一列
                    {
                        this.Hide();
                        Form2 f2 = new Form2();
                        f2.Show();
                    }
                    else
                    {
                        MessageBox.Show("不存在此用户");
                    }
                }
                if (radioButton2.Checked == true)
                {
                    string OleDb= string.Format("select count(*) from Users  where User_id='{0}' and User_password='{1}'and User_power='{2}'", this.textBox1.Text, this.textBox2.Text, 0);


                    OleDbCommand comm = new OleDbCommand(OleDb, conn); // 创建command对象
                    int count = (int)comm.ExecuteScalar();//执行查询,并返回查询
                    if (count == 1)//判断是否存在这样一列
                    {
                        this.Hide();
                        Form8 f8 = new Form8();
                        f8.passbb(textBox1.Text);
                        f8.Show();
                    }
                    else
                    {                        
                        MessageBox.Show("输入有误,请从新输入!");
                    }
                }
            }
            catch(Exception )

            {
                throw new Exception("产生异常!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {


        radioButton1.Checked = true;
            textBox1.Text = "";
            textBox2.Text = "";
            textBox1.Focus();

        }

        private void radioButton2_Click(object sender, EventArgs e)
        {
        textBox1.Focus();
        }

        private void Form1_Click(object sender, EventArgs e)
        {
      
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          textBox1.Focus();
        }


        }
    }
[解决办法]
断点跟进。。
[解决办法]
           catch(Exception )

             {
                 throw new Exception("产生异常!");


             }
=>
           catch(Exception exp)

             {
                 MessageBox.Show(exp.Message);
             }

看看显示什么。
[解决办法]


设个断点,看看在哪停了,看看数据类型输入数据和你定义是否匹配
[解决办法]
问题不明确。
[解决办法]
检查你的SQL 语句  string OleDb= string.Format("select count(*) from Users  where User_id='{0}' and User_password='{1}'and User_power='{2}'", this.textBox1.Text, this.textBox2.Text, 0);
 将SQL 语句放到 access 中运行一下 就知道哪里错了~ 目测是 User_id='{0}' 这里错了 应该改为 User_id={0}  好像 access 中ID值不需要单引号!
[解决办法]
User_power='{2}'", =>User_power={2}", 
[解决办法]

热点排行