![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#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
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