asp 连接数据库的语句

asp 数据库连接
View Code
#region 连接数据库

SqlConnection conn
= new SqlConnection();
//conn.ConnectionString = "server=127.0.0.1\\sqlexpress;uid=sa;pwd=0;database=EXTDatabase";
conn.ConnectionString = ConfigurationManager.ConnectionStrings["stringcon"].ConnectionString;
if (conn.State == ConnectionState.Closed)
conn.Open();
SqlCommand cmd
= new SqlCommand();
cmd.Connection
= conn;
cmd.CommandText
= string.Format(" select * from login where USERID = '{0}' and PASSWORD = '{1}'", UserName, Password);
//object obj = cmd.ExecuteScalar();

SqlDataReader reader
= cmd.ExecuteReader();

if (reader.Read())
{


Session[
"rolevalue"] = reader["RoleValue"].ToString();
Session[
"username"] = reader["USERID"].ToString();
string struser=Session["username"].ToString();

if (Session["username"] != "" && Session["username"] != null)
Response.Write(
"{success:true}");
else
Response.Write(
"{success:false}");
}
else
{
Response.Write(
"{success:false}");
}
if (conn.State != ConnectionState.Closed)
conn.Close();
#endregion
posted on 2011-06-01 15:03  nbfhxy  阅读(205)  评论(0编辑  收藏  举报