日期:2014-05-17  浏览次数:21022 次

WinForm中OleDbDataReader的问题
  public OleDbDataReader ExecuteQueryReturnReader(string sql, string connStr)
        {
            OleDbConnection conn = new OleDbConnection();
            OleDbDataReader reader = null;
            try
            {
                conn = new OleDbConnection(connStr);
                conn.Open();

                OleDbCommand command = conn.CreateCommand();
                command.CommandText = sql;
                reader = command.ExecuteReader();
            }
            catch
            {
            }
            finally
            {
                if (conn != null)
                    conn.Close();
            }
            return reader;
        }      


以上是在下的代码,在项目中是这么使用的:

 string DataBase = "HCConfig.mdb";
            string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                                    + Application.StartupPath + "//" + DataBase;
            ExecSql con = new ExecSql();