| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2228 人关注过本帖
标题:如何连接ACCESS数据库验证登录?
只看楼主 加入收藏
zjdjh
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2005-12-22
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:3 
如何连接ACCESS数据库验证登录?
试了以下代码,提示 OleDbDataReader reader = cmd.ExecuteReader();
这一句错误:
“标准表达式中数据类型不匹配。 ”
请大侠帮忙!!!
 
                    string strPath = Application.StartupPath + "\\gk.mdb";
                    string strconn = "provider=microsoft.jet.oledb.4.0;data source='" + strPath + "'";
                    OleDbConnection oleconn = new OleDbConnection(strconn);
                    
                    string strcmd = "select * from tb_user where username='" + txtuser.Text.Trim() + "'and userpwd='" + txtpwd.Text.Trim() + "' ";
                    OleDbCommand cmd = new OleDbCommand(strcmd, oleconn);
                    oleconn.Open();
                    OleDbDataReader reader =cmd.ExecuteReader();
                    try
                    {
                        reader.Read();
                        if (reader.HasRows)
                        {
                            string pp = txtuser.Text;

                            // Frm_Main newfrm = new Frm_Main(pp);
                            frm_main main = new frm_main();
                            main.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtuser.Text = "";
                            txtpwd.Text = "";
                            txtuser.Focus();
                        }
                    }

                    finally
                    {
                        if (reader != null)
                            oleconn.Close();
                    }


[ 本帖最后由 zjdjh 于 2012-3-12 21:46 编辑 ]
搜索更多相关主题的帖子: 数据库 数据 source 表达式 where 
2012-03-12 21:34
zzqqrr
Rank: 6Rank: 6
来 自:299294817
等 级:侠之大者
威 望:1
帖 子:155
专家分:408
注 册:2011-6-11
收藏
得分:3 
看起来好像没错!

59izk,com神奇百货,神奇百货网官网,shenqi,一个神奇的导购站!!
2012-03-14 22:55
lcawen
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:184
注 册:2011-8-11
收藏
得分:3 
access数据库的后缀名似乎是accdb吧,mdb的是否可以,没有尝试过,楼主看看是否是这个原因
2012-03-15 09:44
zhenggang520
Rank: 1
等 级:新手上路
帖 子:10
专家分:3
注 册:2011-11-30
收藏
得分:3 
你试一下下面这一段!


string strPath = Application.StartupPath + "\\gk.mdb";
                    string strconn = "provider=microsoft.jet.oledb.4.0;data source='" + strPath + "'";
                    OleDbConnection oleconn = new OleDbConnection(strconn);
                    string strcmd = "select * from tb_user where username='" + txtuser.Text.Trim() + "'and  userpwd='" + txtpwd.Text.Trim() + "' ";
                    OleDbCommand cmd = new OleDbCommand();
                      = strcmd;
                    try
                    {
                        
                        if (null == cmd.ExecuteScalar())
                        {
                            string pp = txtuser.Text;

                            // Frm_Main newfrm = new Frm_Main(pp);
                            frm_main main = new frm_main();
                            main.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK,  
MessageBoxIcon.Information);
                            txtuser.Text = "";
                            txtpwd.Text = "";
                            txtuser.Focus();
                        }
                    }
2012-03-15 10:45
快速回复:如何连接ACCESS数据库验证登录?
数据加载中...
 
   



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

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