文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>asp 连接数据库的语句

asp 连接数据库的语句

时间:2011-06-01  来源:nbfhxy


            #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
            #region 连接数据库

SqlConnection conn
= new SqlConnection();
//conn.ConnectionString = "server=127.0.0.1\\sqlexpress;uid=sa;[email protected];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
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载