/// <summary> /// 执行SQL文本,返回DataTable /// </summary> /// <param name="strSQLText">SQL文本</param> /// <returns>DataTable</returns> public static DataTable execQueryBySQLText(string strSQLText) { OleDbCommand comm = DBOper.CreateCommandDBCon(); comm.CommandType = CommandType.Text; comm.CommandText = strSQLText; DataTable table = null; try { comm.Connection.Open(); OleDbDataReader reader = comm.ExecuteReader(); table = new DataTable(); table.Load(reader); reader.Close(); } catch (Exception ex) { throw ex; } finally { comm.Connection.Close(); } return(table); }
/// <summary> /// 执行SQLText脚本,返回影响行数 /// </summary> /// <param name="strSQLText"></param> /// <returns></returns> public static int execNonQueryBySQLText(string strSQLText) { OleDbCommand comm = DBOper.CreateCommandDBCon(); comm.CommandType = CommandType.Text; comm.CommandText = strSQLText; int affectedRows = -1; try { comm.Connection.Open(); affectedRows = comm.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { comm.Connection.Close(); } return(affectedRows); }