public DataSet DataAdapter(CommandType cmdType, string cmdText) { Loghelper.WriteLog("SQL语句: " + cmdText); // we use a try/catch here because if the method throws an exception we want to // close the connection throw code, because no datareader will exist, hence the // commandBehaviour.CloseConnection will not work DbDataAdapter dda = null; try { EstablishFactoryConnection(); dda = oFactory.CreateDataAdapter(); PrepareCommand(mblTransaction, cmdType, cmdText); dda.SelectCommand = oCommand; DataSet ds = new DataSet(); dda.Fill(ds); return(ds); } catch (Exception ex) { Loghelper.WriteLog("错误: " + ex.Message.ToString()); //return null; throw ex; } finally { if (null != oCommand) { oCommand.Dispose(); } CloseFactoryConnection(); } }
public DBHelper(ConnectionStringSettings conectionStringSetting) { S_CONNECTION = conectionStringSetting.ConnectionString; S_PROVIDER = conectionStringSetting.ProviderName; setConnectionType(S_PROVIDER); oFactory = DbProviderFactories.GetFactory(S_PROVIDER); mblTransaction = false; Loghelper.WriteLog("连接参数: " + S_CONNECTION); }
public int ExecuteNonQuery(CommandType cmdType, string cmdText) { try { Loghelper.WriteLog("SQL语句: " + cmdText); EstablishFactoryConnection(); PrepareCommand(false, cmdType, cmdText); return(oCommand.ExecuteNonQuery()); } catch (Exception ex) { Loghelper.WriteLog("错误: " + ex.Message.ToString()); throw ex; } finally { if (null != oCommand) { oCommand.Dispose(); } CloseFactoryConnection(); } }