| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2610 人关注过本帖
标题:请教c#查询access数据
只看楼主 加入收藏
dp85402305
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-9-3
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:5 
请教c#查询access数据
做一个密码验证登陆!连接的是access数据库!有usernam和password  2个textbox还有一个登入button!在access数据库里面已经写好用户名和密码!怎么才能通过button_chick事件判断输入的usernam和passwo是不是在数据库里面的呢!是则通过,否则返回!忘指教下!
搜索更多相关主题的帖子: access 数据 查询 
2009-09-04 16:34
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:3 
找个例子,看看就会了

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-09-04 16:48
田田的猪
Rank: 1
等 级:新手上路
帖 子:1
专家分:3
注 册:2009-9-5
收藏
得分:3 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        SqlConnection objConnection = new SqlConnection(strConnet);
        SqlCommand objCommand = new SqlCommand("", objConnection);
         = "SELECT USERID,NICKNAME,USERROLE FROM USERS WHERE USERNAME=@NAME AND USERPASSWORD=@PASSWORD";
        objCommand.Parameters.Add("NAME",SqlDbType.VarChar);
        objCommand.Parameters.Add("PASSWORD", SqlDbType.VarChar);
        objCommand.Parameters["NAME"].Value = tbxName.Text.Trim();
        objCommand.Parameters["PASSWORD"].Value = tbxPassword.Text.Trim();
        try
        {
            if (objConnection.State == ConnectionState.Closed)
            {
                objConnection.Open();
            }
            SqlDataReader result = objCommand.ExecuteReader();
            if (result.Read() == true)
            {
                Session["USERID"] = result["USERID"].ToString();
                Session["NICKNAME"] = result["NICKNAME"].ToString();
                Session["USERROLE"] = result["USERRILE"].ToString();
                if (Session["USERROLE"].ToString() == "1")
                {
                    Response.Redirect("Manager.aspx");
                }
                else
                {
                    Response.Redirect("Welcom.aspx");
                }
            }
            else
            {
                labError.Visible = true;
            }
        }
上面是我写的一个登录模块的 垃圾代码  用的是SQL
仿照着写 access数据库大概就这个样子
2009-09-05 11:58
jxsfreedom
该用户已被删除
收藏
得分:3 
提示: 作者被禁止或删除 内容自动屏蔽
2009-09-05 22:52
taobin
Rank: 2
来 自:四川
等 级:论坛游民
帖 子:34
专家分:30
注 册:2009-8-28
收藏
得分:3 
private void button1_Click(object sender, EventArgs e)//登录按钮
        {
            if (textBox1.Text.Trim () == ""||textBox2.Text.Trim () == "")
            {
                MessageBox.Show("对不起,你还没有输入用户名和密码", "提示");
                textBox3.Focus();
            }
            else
            {
                    OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库名称");
                    conn.Open();
                    OleDbDataAdapter dauser = new OleDbDataAdapter("Select * from usermessage where username='" + textBox1.Text.Trim() + "'", conn);
                    DataSet dsuser = new DataSet();
                    dauser.Fill(dsuser, "usermessage");
                    if (dsuser.Tables[0].Rows.Count == 0)//判断用户是否存在
                    //用户不存在,给出提示后清空文本框再定位光标到文本框1
                    {
                        MessageBox.Show("对不起,您还没有注册,请先注册", "提示");
                        textBox1.Clear();
                        textBox2.Clear();
                        textBox1.Focus();
                    }
                    else
                    //用户存在,再判断密码是否正确
                    {
                        DataRow[] dr = dsuser.Tables[0].Select("username='" + textBox1.Text + "'");//为取数据表中某列字段内容做准备
                        if ((dr[0]["userpassword"].ToString(), textBox2.Text) == 0)//判断密码是否相等到
                        //密码也正确,则显示登录成功窗体
                        {
                MessageBox.Show("成功", "提示");//也可以写你需要做的事情
                        }
                        else
                            //密码不正确,给出提示,再定位光标重输密码
                        {
                            MessageBox.Show("对不起,密码错误,请重新输入", "提示");
                            textBox2.Clear();
                            textBox2.Focus();
                        }

                    }
                }
               
            }

其实并不可怕
2009-09-06 08:46
taobin
Rank: 2
来 自:四川
等 级:论坛游民
帖 子:34
专家分:30
注 册:2009-8-28
收藏
得分:0 
private void button1_Click(object sender, EventArgs e)//登录按钮
        {
            if (textBox1.Text.Trim () == ""||textBox2.Text.Trim () == "")
            {
                MessageBox.Show("对不起,你还没有输入用户名和密码", "提示");
                textBox3.Focus();
            }
            else
            {
                    OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库名称");
                    conn.Open();
                    OleDbDataAdapter dauser = new OleDbDataAdapter("Select * from usermessage where username='" + textBox1.Text.Trim() + "'", conn);
                    DataSet dsuser = new DataSet();
                    dauser.Fill(dsuser, "usermessage");
                    if (dsuser.Tables[0].Rows.Count == 0)//判断用户是否存在
                    //用户不存在,给出提示后清空文本框再定位光标到文本框1
                    {
                        MessageBox.Show("对不起,您还没有注册,请先注册", "提示");
                        textBox1.Clear();
                        textBox2.Clear();
                        textBox1.Focus();
                    }
                    else
                    //用户存在,再判断密码是否正确
                    {
                        DataRow[] dr = dsuser.Tables[0].Select("username='" + textBox1.Text + "'");//为取数据表中某列字段内容做准备
                        if ((dr[0]["userpassword"].ToString(), textBox2.Text) == 0)//判断密码是否相等到
                        //密码也正确,则显示登录成功窗体
                        {
                MessageBox.Show("成功", "提示");//也可以写你需要做的事情
                        }
                        else
                            //密码不正确,给出提示,再定位光标重输密码
                        {
                            MessageBox.Show("对不起,密码错误,请重新输入", "提示");
                            textBox2.Clear();
                            textBox2.Focus();
                        }

                    }
                }
               
            }

其实并不可怕
2009-09-06 08:48
快速回复:请教c#查询access数据
数据加载中...
 
   



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

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