标题:关于.net+access用户登录问题[求助]
取消只看楼主
jcrystal
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-6-1
 问题点数:0 回复次数:1 
关于.net+access用户登录问题[求助]

不管用户名、密码对不对,都提示”用户名或密码不对“。access数据库为user.mdb
里边的表为user,登录页的代码部分如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Txtuid.Text = "";
this.Txtpwd.Text = "";
}
}

protected void Btny_Click(object sender, EventArgs e)
{
string uid=this.Txtuid.Text;
string pwd=this.Txtpwd.Text;
if (Validate(uid, pwd))
this.Lab1.Text = "成功登录";

else
this.Lab1.Text = "用户名或密码不对";

}
private bool Validate(string id, string password)
{
string strconnection = "provider=microsoft.jet.oledb.4.0;";
strconnection += @"data source=D:\newlog\App_Data\user.mdb";

OleDbConnection con = null;
try
{
DataSet ds = new DataSet();
con = new OleDbConnection(strconnection);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select count(*) as number from user where id=? and password=?";
cmd.Parameters.Add("@id", OleDbType.VarChar, 50).Value = id;
cmd.Parameters.Add("@password", OleDbType.VarChar, 50).Value = password;
cmd.Connection = con;
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
DataRow dr = ds.Tables[0].Rows[0];
int number = Convert.ToInt32(dr["number"].ToString());

if (number == 0)
return false;
else
return true;

}
catch (OleDbException ex)
{
this.Lab1.Text = "错误" + ex.Message;
return false;
}
finally
{
try
{
if (con != null)
con.Close();
}
catch (SqlException ex)
{
this.Lab1.Text = "错误" + ex.Message;

}
}


}

}

搜索更多相关主题的帖子: using System access 数据库 Web 
2007-06-01 23:53
jcrystal
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-6-1
得分:0 
好像还是不行

2007-06-04 23:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-144189-1-1.html




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

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