一个简单的ASP.NET +ACCESS 登录

首页:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:600; text-align: left;">
        <tr>
            <td colspan="3" style="height: 77px">
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </td>
        </tr>
         <tr>
             <td colspan="3">
                 <span style="font-size: 24pt; color: #ff0000">已是会员,请在这里登录</span></td>
         </tr>
         <tr>
             <td style="width: 116px; height: 39px;">
                 <span style="font-size: 16pt">
                 用户名:</span></td>
             <td colspan="2" style="height: 39px">
                 <asp:TextBox ID="TextBox1" runat="server" Width="215px"></asp:TextBox></td>
         </tr>
         <tr>
             <td style="width: 116px; height: 47px;">
                 <span style="font-size: 16pt">
                 密码:</span></td>
             <td colspan="2" style="height: 47px">
                 <asp:TextBox ID="TextBox2" runat="server" Width="214px"></asp:TextBox></td>
         </tr>
         <tr>
             <td style="width: 116px">
             </td>
             <td style="width: 138px">
                 <asp:Button ID="Button1" runat="server" Font-Size="14pt" Text="登 录" Width="89px" OnClick="Button1_Click" /></td>
             <td style="width: 134px">
             </td>
         </tr>
</table>
</div>
    </form>
</body>
</html>

 

登陆后台功能:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.OleDb;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("/WebSite21/App_Data/news.mdb");
        OleDbConnection oleConnection = new OleDbConnection(ConnStr);
        oleConnection.Open();
        OleDbCommand mycommand = new OleDbCommand("select * from login where username='" + TextBox1.Text + "' and userpwd='" + TextBox2.Text + "'", oleConnection);
        int count = Convert.ToInt32(mycommand.ExecuteScalar());
        if (count > 0)
        {
            Session["name"] = TextBox1.Text;

            Response.Redirect("cg.aspx");
        }
        else
        {
            Label1.Text = "<script language=javascript>alert( '用户名或密码错误')</script>";
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox1.Focus();
        }
        oleConnection.Close();

    }
}

 

 

登陆成功后转向cg.aspx页面

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class cg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Session["name"]);
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hbqjzx

你的鼓励将是我分享的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值