关于关闭数据库和关闭连接!!!!
这是DATA.CS类
public static string connection()
{
connstr = ConfigurationManager.AppSettings[ "databasestr "].ToString();
return connstr;
}
public static SqlDataReader operator_selectonlyread(string sqlstr)
{
connstr=connection();
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlDataReader read = cmd.ExecuteReader();
return read;
}
这是另一个类文件(find.cs),在此调用上边的类的一个方法
public static int LandingConfirmation(string username,string userpassword)
{
sqlstr = "select top 1 * from manager where account= ' " + username + " ' and pwd= ' " + userpassword+ " ' ";
if (Data.operator_selectonlyread(sqlstr).Read())
{
result = 1 }
else
{
result = 0;
}
return result;
}
我想问一下应该在哪关闭数据库和连接啊 该怎么关闭 谢谢
------解决方案--------------------hertcloud(·£孙子兵法£·) ( ) 信誉:100 Blog 2007-04-03 11:57:29 得分: 0
SqlDataReader read = cmd.ExecuteReader();
---->
cmd.ExecuteReader(CommandBehavior.CloseConnection);
SqlDataReader dr = Data.operator_selectonlyread(sqlstr);
if (dr.Read())
{
result = 1 }
else
{
result = 0;
}
dr.Close();
return result;
---------------------------------
up
------解决方案-------------------- public static SqlDataReader operator_selectonlyread(string sqlstr)
{
connstr=connection();
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sqlstr, conn);