| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 277 人关注过本帖
标题:请帮我看看错在哪里!
只看楼主 加入收藏
dp85402305
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-9-3
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:1 
请帮我看看错在哪里!
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Data .OleDb ;
namespace 学生信息管理系统
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            if (() == "管理员")
            {
                Usertextbox.Text = "administrator";
                Passwordbox.Text = "ttxlla";
            }
            if (() == "教师")
            {
                Usertextbox.Text = "teacher";
                Passwordbox.Text = "teacher";
            }
            if (() == "学生")
            {
                Usertextbox.Text = "student";
                Passwordbox.Text = "student";
            }
            else if (() == "游客")
            {
                Usertextbox.Text = "您将以游客身份登录!";
                Passwordbox.Text = "guest";
            }
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Sure Out?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label5.Text = "Time is:" + System.DateTime.Now.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (Usertextbox.Text.Trim() == "" || Passwordbox.Text.Trim() == "")
            {
                MessageBox.Show("Sorry!You hane not import your username or your password!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Usertextbox.Focus();
            }
            else
            {
                string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;";
                strConnection += "Data Source=";
                strConnection += Application.StartupPath;
                strConnection += @"\学生信息.mdb";
                OleDbConnection conn = new OleDbConnection(strConnection);
                conn.Open();
                OleDbDataAdapter dauser = new OleDbDataAdapter("select * from 学生信息表 where 用户名='" +Usertextbox . Text.Trim() + "'+  密码='"+Passwordbox .Text .Trim ()+"'+  身份='"+comboBox1 .Text .Trim ()+"'", conn);
                DataSet dsuser = new DataSet();
                dauser.Fill(dsuser, "学生信息表");

                if (dsuser.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("Sorry!Wrong usernam!", "message",MessageBoxButtons .OK ,MessageBoxIcon.Error );
                    Usertextbox.Clear();
                    Passwordbox.Clear();
                    Usertextbox .Focus ();
                }
                else
                {
                    DataRow[] dr = dsuser.Tables[0].Select("用户名='" +Usertextbox . Text + "'");
                    if ((dr[0]["密码"].ToString(),Passwordbox . Text) == 0)
                    {
                        MessageBox.Show("Success!", "message",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
                    }  
                    else
                    {
                        MessageBox.Show("Wrong password!", "message",MessageBoxButtons .OK ,MessageBoxIcon.Error );
                       Passwordbox . Clear();
                       Passwordbox . Focus();
                    }
                }

            }
        }
    }
}


这是学校布置的一个作业!我运行的话没有报错!我输入错误的usernam说账号错误!但是就算我输入了正确的账号密码也是账号错误!就好像程序只运行到MessageBox.Show("Sorry!Wrong usernam!", "message",MessageBoxButtons .OK ,MessageBoxIcon.Error );地方一样!请教大虾们!这个程序错在哪里!<我的combobox功能现在可以不考虑!>
搜索更多相关主题的帖子: private 管理系统 public 信息 
2009-09-07 01:07
baikil
Rank: 10Rank: 10Rank: 10
来 自:X星球
等 级:青峰侠
威 望:4
帖 子:282
专家分:1580
注 册:2009-7-20
收藏
得分:20 
OleDbDataAdapter dauser = new OleDbDataAdapter("select * from 学生信息表 where 用户名='" +Usertextbox . Text.Trim() + "'+  密码='"+Passwordbox .Text .Trim ()+"'+  身份='"+comboBox1 .Text .Trim ()+"'", conn);
--->这是你不是用了用户名与密码都存在,dauser的数目大于0的话就是能过了验证了吗.
不过好像你的SQL语句有点问题.
-->OleDbDataAdapter dauser = new OleDbDataAdapter("select * from 学生信息表 where 用户名='" +Usertextbox . Text.Trim() + "'+ and 密码='"+Passwordbox .Text .Trim ()+"'+ and 身份='"+comboBox1 .Text .Trim ()+"'", conn);

--> select [字段1],[字段2]...where [条件1] and/or[条件2]  ...
--->所以后面只须判断是否为空就可以决定是否通过验证.

自创QQ群64885635,方便C#学习交流.希望各项工作路好学都好入!
2009-09-07 08:35
快速回复:请帮我看看错在哪里!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045937 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved