ASP.NET c#连接ACCESS数据库的登陆按钮代码

2024-12-15 01:12:50
推荐回答(3个)
回答1:

protected void Button1_Click(object sender, EventArgs e)
{
string UserName = this.username.Text;
string PassWord = this.password.Text;
string connstr = "provider=microsoft.jet.oledb.4.0;data source="+ Server.MapPath("zhongtian_site.mdb");
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();

int count = 0;

string sql = string.Format("select count(*) from table where userName ='{0}' and userPwd={1}",UserName ,PassWord );
SqlCommand command = new SqlCommand(sql,connstr);
try
{
conn.Open();
count = (int)command.ExecuteScalar();
if (count == 1)
{
Response.Redirect("形态中心2.aspx");
}
else
{
Response.Write("密码或帐号错误");
}
}
catch(Exception ex)
{
Response.Write("密码或帐号错误");
}
finally
{
conn.Close();
}
}

回答2:

<%@ Page Language="C#" Debug="true" %>

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>











登录名


密 码









回答3:

加断点试试 看看具体哪里的问题?