public string ExecScalar(SqlCommand sCommand) { SqlConnection sConnection = new ClassFuncoes().GetConexaoBD(); string sRetorno = ""; try { sConnection.Open(); sCommand.Connection = sConnection; sCommand.Prepare(); sRetorno = sCommand.ExecuteScalar().ToString(); } catch { } finally { if (sConnection.State == ConnectionState.Open) { sConnection.Close(); } } return(sRetorno); }
public string ExecNonQuery(SqlCommand sCommand) { string sRetorno = ""; SqlConnection sConnection = new ClassFuncoes().GetConexaoBD(); try { sConnection.Open(); sCommand.Connection = sConnection; sCommand.Prepare(); sCommand.ExecuteNonQuery(); } catch (Exception ex) { sRetorno = ex.Message; } finally { if (sConnection.State == ConnectionState.Open) { sConnection.Close(); } } return(sRetorno); }
public DataTable ExecReader(SqlCommand sCommand) { SqlConnection sConnection = new ClassFuncoes().GetConexaoBD(); DataTable tblRetorno = new DataTable(); try { sConnection.Open(); sCommand.Connection = sConnection; sCommand.Prepare(); SqlDataReader rReader = sCommand.ExecuteReader(CommandBehavior.CloseConnection); tblRetorno.Load(rReader); } catch { } finally { if (sConnection.State == ConnectionState.Open) { sConnection.Close(); } } return(tblRetorno); }
public string ExecNonQuery(SqlCommand sCommand, SqlCommand sCommand1) { string sRetorno = ""; SqlConnection sConnection = new ClassFuncoes().GetConexaoBD(); sConnection.Open(); sCommand.Connection = sConnection; sCommand1.Connection = sConnection; sCommand.Prepare(); sCommand1.Prepare(); SqlTransaction objTrans = sConnection.BeginTransaction(); sCommand.Transaction = objTrans; sCommand1.Transaction = objTrans; try { sCommand.ExecuteNonQuery(); sCommand1.ExecuteNonQuery(); objTrans.Commit(); } catch (Exception ex) { objTrans.Rollback(); sRetorno = ex.Message; } finally { if (sConnection.State == ConnectionState.Open) { sConnection.Close(); } } return(sRetorno); }