| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 875 人关注过本帖
标题:求助登录验证模块
只看楼主 加入收藏
xiaguozhix
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-9-23
收藏
 问题点数:0 回复次数:5 
求助登录验证模块
using System;
using System.Collections;
using
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace LiuYanBan
{
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.Label Label2;
        protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.TextBox TextBox2;
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Button Button2;
        protected System.Web.UI.WebControls.LinkButton LinkButton1;
        protected System.Web.UI.WebControls.Label Label3;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {   
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Button2.Click += new System.EventHandler(this.Button2_Click);
            this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Button1_Click(object sender, System.EventArgs e)
       {
            try
            {
                //进行数据库的连接
                string strconn="server=E4D8FD724D41443;uid=sa;pwd=sa;database=DataBase";
                string strcmd="select count(*) from User where (UserName like '" +TextBox1.Text+ " ' and Pwd like'" +TextBox2.Text+ "')";
                //string strCmd = "select count(*) from book where (name like'" + TextBox1.Text + "' and password like'" + TextBox2.Text + "')";

                SqlConnection myconnection=new SqlConnection();
                myconnection.ConnectionString=strconn;
                SqlCommand mycommand=new SqlCommand(strcmd,myconnection);
                mycommand.Connection.Open();
                int flag=(int)mycommand.ExecuteScalar();
                mycommand.Connection.Close();
                myconnection.Close();

                if(flag>0)//用户存在的话
                {
                    Session["UserName"]=TextBox1.Text;
                    Response.Redirect("WebForm3.aspx");            
                }
                else
                {
                    Label3.Text="对不起!用户名密码不符";
                    TextBox1.Text="";
                    TextBox2.Text="";            
                }
            }
            catch
            {
                    Label3.Text="出现问题了";            
            }






        }
搜索更多相关主题的帖子: 模块 验证 登录 
2008-10-06 10:08
xiaguozhix
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-9-23
收藏
得分:0 
各位大侠!  程序段不能执行是怎么回事啊?  急求助!!!
2008-10-06 10:10
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
能告诉我出现什么错误了吗?
2008-10-06 13:39
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
还有就是你where的时候为什么要用()?
2008-10-06 13:40
夜の枫
Rank: 2
来 自:深圳
等 级:新手上路
威 望:3
帖 子:98
专家分:0
注 册:2008-9-15
收藏
得分:0 
哪里有问题啊???
2008-10-06 14:13
xiaguozhix
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-9-23
收藏
得分:0 
已经解决了
我在SQL数据库上搞错了  谢谢各位啊
2008-10-07 22:06
快速回复:求助登录验证模块
数据加载中...
 
   



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

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