• 大小: 188KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: 数据库
  • 标签: C#  

资源简介

目的:如何在网页中用用户名和密码登陆并显示目标数据库的内容。实例中显示的是一个出版社的表格,同时网页也有自己相应的格式

资源截图

代码片段和文件信息

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.SqlClient;

namespace DatabaseAccessWeb
{
    public partial class login : System.Web.UI.Page
    {     
        //定义连接对象
            SqlConnection myconnection;

       
        //定义Command对象
           SqlCommand sqlcmd;
        protected void Page_Load(object sender EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender AuthenticateEventArgs e)
        {
                string connectionstr = ConfigurationManager.ConnectionStrings[“pubsConnectionString“].ConnectionString;
                myconnection = new SqlConnection(connectionstr);
                string sqlstatement = “select count(userid) from MyTable_userverify where userid=@userid and password=@password “;
                sqlcmd = new SqlCommand(sqlstatement myconnection);
                sqlcmd.Parameters.AddWithValue(“@userid“ Login1.UserName.ToString());
                sqlcmd.Parameters.AddWithValue(“@password“ Login1.Password.ToString());

                try
                {
                    myconnection.Open();
                    //获取对应店号的记录数,如果不为0,则表示数据库中已存在此店号。
                    int rowcount = int.Parse(sqlcmd.ExecuteScalar().ToString());
                    if (rowcount > 0)
                    {
                        Session[“username“] = Login1.UserName.ToString();

                        Response.Redirect(“stores.aspx“);
                    }
                }
                catch (SqlException ee)
                {
                    lbl_result.Text = “数据库查询失败:“ + ee.Message;
                }
                finally
                {
                    myconnection.Close();
                }
            }
        
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\bin\
     文件       20480  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\bin\DatabaseAccessWeb.dll
     文件       24064  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\bin\DatabaseAccessWeb.pdb
     文件        3972  2007-12-13 20:27  DatabaseAccessWeb\DatabaseAccessWeb\DatabaseAccessWeb.csproj
     文件        1140  2007-12-13 20:27  DatabaseAccessWeb\DatabaseAccessWeb\DatabaseAccessWeb.csproj.user
     文件        1712  2007-12-13 20:45  DatabaseAccessWeb\DatabaseAccessWeb\login.aspx
     文件        2068  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\login.aspx.cs
     文件        1655  2007-12-13 16:53  DatabaseAccessWeb\DatabaseAccessWeb\login.aspx.designer.cs
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\obj\
     文件         162  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\obj\DatabaseAccessWeb.csproj.FileList.txt
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\obj\Debug\
     文件       20480  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\obj\Debug\DatabaseAccessWeb.dll
     文件       24064  2007-12-13 20:47  DatabaseAccessWeb\DatabaseAccessWeb\obj\Debug\DatabaseAccessWeb.pdb
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\obj\Debug\TempPE\
     文件        3673  2007-12-13 17:31  DatabaseAccessWeb\DatabaseAccessWeb\Order.aspx
     文件         674  2007-12-13 17:27  DatabaseAccessWeb\DatabaseAccessWeb\Order.aspx.cs
     文件        2375  2007-12-13 17:22  DatabaseAccessWeb\DatabaseAccessWeb\Order.aspx.designer.cs
     目录           0  2009-05-04 23:52  DatabaseAccessWeb\DatabaseAccessWeb\Properties\
     文件        1328  2007-12-12 10:16  DatabaseAccessWeb\DatabaseAccessWeb\Properties\AssemblyInfo.cs
     文件       10699  2007-12-13 20:27  DatabaseAccessWeb\DatabaseAccessWeb\stores.aspx
     文件        8692  2007-12-13 20:30  DatabaseAccessWeb\DatabaseAccessWeb\stores.aspx.cs
     文件        7980  2007-12-13 19:46  DatabaseAccessWeb\DatabaseAccessWeb\stores.aspx.designer.cs
     文件        1459  2007-12-12 10:33  DatabaseAccessWeb\DatabaseAccessWeb\Web.config
     文件        1090  2007-12-12 10:16  DatabaseAccessWeb\DatabaseAccessWeb.sln
     文件       19456  2007-12-13 20:30  DatabaseAccessWeb\DatabaseAccessWeb.suo
     文件      213504  2009-05-04 23:56  实验五.doc

评论

共有 条评论