public static List <Glossario> Listar(Glossario objGlossario) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_GLOSSARIO"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; if (objGlossario.IdiomaId > 0) { objComando.Parameters.Add("@idiomaId", SqlDbType.Int).Value = objGlossario.IdiomaId; } if (objGlossario.Titulo != null && objGlossario.Titulo.Length > 0) { objComando.Parameters.Add("@titulo", SqlDbType.VarChar, 50).Value = objGlossario.Titulo; } try { //Abre Conexao objConexao.Open(); //Declara variavel de retorno List <Glossario> objList = new List <Glossario>(); Glossario obj = default(Glossario); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { obj = new Glossario(); obj.FromIDataReader(idrReader); objList.Add(obj); } return(objList); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }
public static Glossario Obter(Glossario objGlossario) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_GLOSSARIO"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; objComando.Parameters.Add("@glossarioId", SqlDbType.Int).Value = objGlossario.Id; try { //Abre Conexao objConexao.Open(); //Declara variavel de retorno Glossario obj = default(Glossario); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); obj = new Glossario(); while ((idrReader.Read())) { obj.FromIDataReader(idrReader); } return(obj); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }