[登录]asp.net登录窗口代码

作者: unvs 分类: ASP.NET 发布时间: 2009-10-16 16:58 ė11,778 views 6没有评论

else
{
string name;
string psw;
SqlDataReader myr;
psw=TextBox2.Text;
name=TextBox1.Text;
string strsql = “SELECT * FROM users WHERE user=’” + name + “‘”;
sql dbo = new sql();
LinkButton1.Text = “cgong”;
myr = dbo.GetResultAsDataReader(strsql);
if (myr.Read())
{
string psw2 = myr["password"].ToString();
if (psw == psw2)
{
Session["name"] = name;
Response.Redirect(“index.aspx”);
myr.Close();
myr.Dispose();
dbo.killMe();

}
else
{
Label3.Text = “密码错误!”;
myr.Close();
myr.Dispose();
dbo.killMe();
}
}
else
{
Label3.Text = “用户不存在!”;
myr.Close();
myr.Dispose();
dbo.killMe();
}

}
}

}

Webconfig代码:
using System;
using System.Data;
using System.Configuration;
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;

///
/// sql 的摘要说明
///
public class sql
{
public SqlConnection con;
public sql()
{
//
// TODO: 在此处添加构造函数逻辑
//
con = new SqlConnection(“server=.sqlexpress;user id=sa;password=7830895;database=shop”);
con.Open();
}

public SqlDataReader GetResultAsDataReader(string strSql)
{
SqlCommand cmd = new SqlCommand(strSql, con);
if (con.State == ConnectionState.Closed)
con.Open();
return cmd.ExecuteReader();
}
public string ExecuteNoReturn(string strSql, string strTip)
{
string strReturn;//创建定义;
SqlCommand myCommand = new SqlCommand(strSql, con);//创建命令;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
myCommand.ExecuteNonQuery();
strReturn = strTip + “成功”;
}
catch
{
strReturn = strTip + “失败”;
}
myCommand.Dispose();
con.Close();
return strReturn;
}
public void killMe()
{
con.Dispose();
}
}

本博文章基本上属于原创或收集整理,都是心血结晶。
欢迎转载分享,转载请注明出处,谢谢!
本文地址:[登录]asp.net登录窗口代码

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Ɣ回顶部