Code
配置文件中连接数据库
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=test;uid=sa;pwd=sa;"/>
</connectionStrings>
//@ConnectionString为配置文件中的name
private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
public int select(string name, string pwd)
{
SqlCommand mycommand = new SqlCommand("sq_selectuser", conn);
mycommand.CommandType = CommandType.StoredProcedure;
//@username对应存储过程
mycommand.Parameters.Add("@username", SqlDbType.VarChar, 15).Value = name;
//@userpassword对应存储过程
mycommand.Parameters.Add("@userpassword", SqlDbType.VarChar, 15).Value = pwd;
conn.Open();
SqlDataReader thisreader = mycommand.ExecuteReader();
if (thisreader.Read())
{
thisreader.Close();
return 1;
}
else
thisreader.Close();
return 0;
}
配置文件中连接数据库
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=test;uid=sa;pwd=sa;"/>
</connectionStrings>
//@ConnectionString为配置文件中的name
private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
public int select(string name, string pwd)
{
SqlCommand mycommand = new SqlCommand("sq_selectuser", conn);
mycommand.CommandType = CommandType.StoredProcedure;
//@username对应存储过程
mycommand.Parameters.Add("@username", SqlDbType.VarChar, 15).Value = name;
//@userpassword对应存储过程
mycommand.Parameters.Add("@userpassword", SqlDbType.VarChar, 15).Value = pwd;
conn.Open();
SqlDataReader thisreader = mycommand.ExecuteReader();
if (thisreader.Read())
{
thisreader.Close();
return 1;
}
else
thisreader.Close();
return 0;
}