日期:2014-05-18  浏览次数:20443 次

阅读器关闭时尝试调用 Read 无效。急!
数据库类,
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.OleDb;
//using System.Data.SqlClient;

/// <summary>
///WebData 的摘要说明
/// </summary>
public class WebData
{

public WebData()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
  

  /// <summary> 
  /// 执行Sql查询语句 
  /// </summary> 
  /// <param name="sqlstr">传入的Sql语句</param> 
  /// 执行SQL语句,返回影响的记录数
  /// </summary>
  /// <param name="SQLString">SQL语句</param>
  /// <returns>影响的记录数</returns>
  public static int ExecuteSql(string sqlstr)
  {
  using(OleDbConnection conn=new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["webtest"].ConnectionString))
  {
  using (OleDbCommand cmd = new OleDbCommand(sqlstr, conn))
  {
  try
  {
  conn.Open();
  int rows = cmd.ExecuteNonQuery();
  return rows;
  }
  catch (System.Data.OleDb.OleDbException e)
  {
  conn.Close();
  throw e;
  }
  finally
  {
  cmd.Dispose();
  conn.Close();
  }
  }
  }
  }


  /// <summary> 
  /// 执行Sql更新语句 
  /// </summary> 
  /// <param name="sqlstr">传入的Sql语句</param>
  /// <returns>布尔值</returns>
  public static int ExecuteUpdate(string sqlstr)
  {
  using(OleDbConnection conn=new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["webtest"].ConnectionString))
  {
  using (OleDbCommand cmd = new OleDbCommand(sqlstr, conn))
  {
  try
  {
  conn.Open();
  int rows = cmd.ExecuteNonQuery();
  return rows;
  }
  catch (System.Data.OleDb.OleDbException e)
  {
  conn.Close();
  throw e;
  }
  finally
  {
  cmd.Dispose();
  conn.Close();
  }
  }
  }

  }



/// <summary>
/// 返回指定Sql语句的SqlDataReader,请注意,在使用后请关闭本对象,同时将自动调用closeConnection()来关闭数据库连接
/// 方法关闭数据库连接
/// </summary>
/// <param name="sqlstr">传入的Sql语句</param>
/// <returns>SqlDataReader对象</returns>
public static OleDbDataReader dataReader(string sqls