• 登录+注册+查询页面


    数据库模型类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    
    /// <summary>
    /// Users 的摘要说明
    /// </summary>
    public class Users
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public Users()
        {
            conn = new SqlConnection("server=.;database=Data0425;user=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
    
        public string UserName { get; set; }
        public string PassWord { get; set; }
        public string NickName { get; set; }
        public bool Sex { get; set; }
        public DateTime Birthday { get; set; }
        public string Nation { get; set; }
    
        public string SexStr {
            get {
                return Sex ? "" : "";
            }
        }
    
        public string NationName {
            get {
                string end = "<无>";
    
                cmd.CommandText = "select *from Nation where NationCode=@a";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@a", Nation);
    
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    end = dr["NationName"].ToString();
                }
                conn.Close();
    
                return end;
            }
        }
    
    
    }

    数据

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    
    /// <summary>
    /// UsersData 的摘要说明
    /// </summary>
    public class UsersData
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public UsersData()
        {
            conn = new SqlConnection("server=.;database=Data0425;usser=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
        public bool SelectUsers(string uname, string upass)
        {
            bool has = false;
            cmd.CommandText = "select * from users where username=@a and password=@b";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@a", uname);
            cmd.Parameters.Add("@b", upass);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                has = true;
            }
            conn.Close();
            return has;
        }
        /// <summary>
        /// 查询全部的USERS信息
        /// </summary>
        /// <returns></returns>
        public List<Users> SelectAll()
        {
            List<Users> list = new List<UsersData>();
            cmd.CommandText="select * from Users";
            conn.Open();
            SqlDataAdapter dr=cmd.ExecuteReader();
        }
        if (dr.hasrows)
    {
           Users u=new Users();
           u.username =dr[0].tostring();
           u.password=dr[1].tostring();
           u.nickname=dr[2].tostring();
           u.sex=Convert.ToBoolean(dr[3]);
           u.birthday=Convert.ToDateTime(dr[4]);
           u.nation=dr[5].Tostring();
           List.Add(u);
    }
    }
    conn.close();
    return list;

    主页操作

    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    
        <style type="text/css">
            table {
                background-color: navy;
                 100%;
            }
    
            #tr_head {
                color: white;
                font-size: 16px;
                text-align: center;
                font-family: 微软雅黑;
            }
    
            .tr_item {
                background-color: white;
                text-align: center;
            }
    
            td {
                padding: 10px;
            }
            .tr_alt {
                background-color:#e0e0e0;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <h1>这里是主页面</h1>
            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr id="tr_head">
                            <td style=" 15%;">用户名</td>
                            <td style=" 15%;">密码</td>
                            <td style=" 15%;">昵称</td>
                            <td style=" 15%;">性别</td>
                            <td style=" 25%;">生日</td>
                            <td style=" 15%;">民族</td>
                        </tr>
                </HeaderTemplate>
                <AlternatingItemTemplate>
                    <tr class="tr_item tr_alt" style="<%# ShowRed() %><%# ShowBold() %>">
                        <td><%#Eval("UserName") %></td>
                        <td><%#Eval("PassWord") %></td>
                        <td><%#Eval("NickName") %></td>
                        <td>
                            <img src="<%# SexImg() %>" /></td>
                        <td><%#Eval("Birthday","{0:yyyy年MM月dd日}") %></td>
                        <td><%#Eval("NationName") %></td>
                    </tr>
                </AlternatingItemTemplate>
                <ItemTemplate>
                    <tr class="tr_item" style="<%# ShowRed() %><%# ShowBold() %>">
                        <td><%#Eval("UserName") %></td>
                        <td><%#Eval("PassWord") %></td>
                        <td><%#Eval("NickName") %></td>
                        <td>
                            <img src="<%# SexImg() %>" /></td>
                        <td><%#Eval("Birthday","{0:yyyy年MM月dd日}") %></td>
                        <td><%#Eval("NationName") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
    
        </form>
    </body>
    </html>
  • 相关阅读:
    fedora上部署ASP.NET——(卡带式电脑跑.NET WEB服务器)
    SQL Server 请求失败或服务未及时响应。有关详细信息,请参见事件日志或其它适合的错误日志
    8086CPU的出栈(pop)和入栈(push) 都是以字为单位进行的
    FTP 服务搭建后不能访问问题解决
    指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配
    Linux 安装MongoDB 并设置防火墙,使用远程客户端访问
    svn Please execute the 'Cleanup' command. 问题解决
    .net 操作MongoDB 基础
    oracle 使用绑定变量极大的提升性能
    尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
  • 原文地址:https://www.cnblogs.com/suiyuejinghao123/p/5677737.html
Copyright © 2020-2023  润新知