public List <string> CE_programa_instituicao(string Query, string[] Coluna, string[] Filtros) { Ender_Banco Conexao = new Ender_Banco(); List <string> Valid = new List <string>(); OdbcConnection Data_Conection = new OdbcConnection(Conexao.Conexao_Banco); OdbcCommand command = new OdbcCommand(Query, Data_Conection); try { Data_Conection.Open(); command.CommandText = Query; for (int cont = 0; cont < Coluna.Count(); cont++) { command.Parameters.AddWithValue("@" + Coluna[cont], Filtros[cont]); } command.ExecuteNonQuery(); OdbcDataReader Reader = command.ExecuteReader(); while (Reader.Read()) { Valid.Add(Reader.GetInt16(0).ToString()); Valid.Add(Reader.GetInt16(1).ToString()); Valid.Add(Reader.GetString(2).ToString()); } } catch (OdbcException Erro) { Valid.Add(Erro.Message); } finally { Data_Conection.Close(); } return(Valid); }
/// <summary> /// Constructs a user from the output of a datareader. Assumes that there is data /// ready to be read from the current record 14/12/15 /// </summary> private static User readUser(OdbcDataReader dataReader) { return(new User(dataReader.GetInt16(0), dataReader.GetString(1), dataReader.GetString(3), dataReader.GetString(4), dataReader.GetString(5), dataReader.GetBoolean(6), dataReader.GetDateTime(7), dataReader.GetInt16(8), dataReader.GetInt16(9), dataReader.GetBoolean(10), dataReader.GetBoolean(11), dataReader.GetInt16(13))); }
private void ninguno() { if (string.IsNullOrWhiteSpace(txt_precio1.Text)) { MessageBox.Show("Campo obligatorio vacío", "Campo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Cambiando precio..."); string scad = "select * from producto"; OdbcCommand mcd = new OdbcCommand(scad, Conexion.ObtenerConexion()); OdbcDataReader mdr = mcd.ExecuteReader(); int j = 1; string scad4 = "DELETE FROM precio where id_tipo = " + codtipo; OdbcCommand mcd4 = new OdbcCommand(scad4, Conexion.ObtenerConexion()); OdbcDataReader mdr4 = mcd4.ExecuteReader(); while (mdr.Read()) { float costo = Convert.ToInt32(mdr.GetDouble(4)); float costo2 = Convert.ToInt32(txt_precio1.Text); float mult = costo * (costo2 / 100); float total = mult + (Convert.ToInt32(costo)); string scad3 = "SELECT id_marca, id_categoria from producto where id_producto='" + j + "'"; OdbcCommand mcd3 = new OdbcCommand(scad3, Conexion.ObtenerConexion()); OdbcDataReader mdr3 = mcd3.ExecuteReader(); if (mdr3.Read()) { codm = mdr3.GetInt16(0); codc = mdr3.GetInt16(1); } OdbcCommand mcd2 = new OdbcCommand( string.Format("insert into precio (precio, id_bien, id_tipo, id_marca, id_categoria) values ('{0}','{1}','{2}','{3}','{4}')", total, j, codtipo, codm, codc), Conexion.ObtenerConexion()); OdbcDataReader mdr2 = mcd2.ExecuteReader(); j++; costo = 0; costo2 = 0; mult = 0; total = 0; codm = 0; codc = 0; } MessageBox.Show("Precios modificados... presione Actualizar"); codtipo = 0; } }
/// <summary> /// DisplayRecords: This function displays the records in the view if any. /// </summary> static void DisplayRecords() { Console.Write("\tRecords in Prescirption list..."); try { reader = (OdbcDataReader)command.ExecuteReader(); // read the returned resultset while (reader.Read()) { /* * This view consists the following fields: * rxdef_id (TINYINT) * drug_name (CHARACTER 50) * description (CHARACTER 50) * rx_date (DATE) * For the purpose of keeping it simple, we are displaying the rxdef_id and drug_name on the console (the first two fields) */ Console.WriteLine("\n\t\t{0} {1} ", reader.GetInt16(0), reader.GetString(1)); } // close the reader reader.Close(); } catch (Exception e) { ExceptionDisplay(e); } }
protected void ddJuegos_SelectedIndexChanged(object sender, EventArgs e) { //Una conexion OdbcConnection miConexion = conectarBD(); if (miConexion != null) { String var1 = ddJuegos.SelectedValue; String query = "select claveJ from juegos where nombre='" + var1 + "'"; //ahora la clave J OdbcCommand cmd = new OdbcCommand(query, miConexion); OdbcDataReader rd = cmd.ExecuteReader(); rd.Read(); //lo que se trajo el reader lo voy a guardar en: int clavej = rd.GetInt16(0); //OTRO STRING QUERY String query2 = "select critica.contentido from critica where critica.claveC=(select claveC from escriben where escriben.claveU=" + Session["cu"].ToString() + "and escriben.claveJ=" + clavej + ")"; OdbcCommand cmd2 = new OdbcCommand(query2, miConexion); OdbcDataReader rd2 = cmd2.ExecuteReader(); rd2.Read(); lbCritica.Text = rd2.GetString(0); rd.Close(); rd2.Close(); } }
static public void case_GetInt16_OverBound_Max() { // Open Connection string strConn = connString; OdbcConnection connCubrid = conn; int test_int = Int16.MaxValue + 1; //Int32 32768 string testTable = "t_type_int16_overbound"; string strCreateTable = string.Format("CREATE TABLE {0}(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f_int INT)", testTable); string strDropTable = string.Format("DROP TABLE {0}", testTable); string strSqlInsert = string.Format("INSERT INTO {0}(f_int) VALUE({1})", testTable, test_int); ExecuteMultiQueries(connCubrid, new string[] { strDropTable, strCreateTable, strSqlInsert }); string strSqlSelect = string.Format("SELECT f_int FROM {0} ORDER BY id DESC;", testTable); OdbcDataReader odbcReader = CreateReader(connCubrid, strSqlSelect); // Int16 result = odbcReader.GetInt16(0); Console.WriteLine(test_int); // output: 32768 try { Console.WriteLine(odbcReader.GetInt16(0)); // output: -32768, expected result: OdbcException } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public List <Municipality> Read_mnps_of_dpt(byte dpt_id) { List <Municipality> municipalities = new List <Municipality>(); try { Database.Connect(); command = new OdbcCommand() { Connection = Database.GetConn(), CommandType = CommandType.StoredProcedure, CommandText = "{call csg.Municipality_ReadMnpOfDpt(?)}" }; command.Parameters.Add("DptId", OdbcType.TinyInt).Value = dpt_id; dataReader = command.ExecuteReader(); while (dataReader.Read()) { Municipality municipality = new Municipality() { Id = dataReader.GetInt16(0), Name = dataReader.GetString(1) }; municipalities.Add(municipality); } } catch (Exception ex) { Console.WriteLine("Excepcione en MunicipalityDAO->Read_mnps_of_dpt: " + ex.Message); } finally { Database.Disconnect(); } return(municipalities); }
private void Btn_ingresar_Click(object sender, EventArgs e) { habilitarBotones(); bloquearBotones(); Txt_nombreArbitro.Text = ""; Txt_apellidoArbitro.Text = ""; Cbo_deporte.Text = ""; Gpb_estado.Enabled = false; boton_ingreso = true; try { int scodigoCampo = 0; OdbcCommand sql = new OdbcCommand("SELECT MAX(PK_idArbitro) FROM tbl_arbitros", nueva.conectar()); OdbcDataReader almacena = sql.ExecuteReader(); while (almacena.Read() == true) { scodigoCampo = almacena.GetInt16(0); } string sSumaCodigo = " "; sSumaCodigo = Convert.ToString(scodigoCampo + 1); Txt_codigoArbitro.Text = sSumaCodigo; almacena.Close(); sql.Connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Returns the ranking of the current rank. Example: Would return 1 for Inigma, assuming /// default dataset. 15/12/15 /// </summary> public static int GetRankRanking(Rank rank) { // Get the number of ranks where the MinScore is below the current rank's MinScore string query = "SELECT COUNT(0) FROM `" + ranksTable + "` WHERE `MinScore`<'" + rank.MinScore + "'"; int ranking = 0; // Create a database command from the query and existing connection OdbcCommand cmd = new OdbcCommand(query, connection); if (connectionOpen()) { try { // Execute the command and open a reader OdbcDataReader dataReader = cmd.ExecuteReader(); // If any data was returned by the reader.. if (dataReader.HasRows) { // Advance to first record dataReader.Read(); // Read the ranking ranking = dataReader.GetInt16(0); // Close the reader dataReader.Close(); } } catch (OdbcException ex) { // Displays an error if something bad occurs while executing the command error = ex.Message; } } // Return the number of ranks with lower minScore + 1 for ranking position return(ranking + 1); }
public static int GetLastInsertID() { string query = "SELECT last_insert_id()"; OdbcCommand cmd = new OdbcCommand(query, connection); int id = -1; if (connectionOpen()) { try { OdbcDataReader dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) { dataReader.Read(); id = dataReader.GetInt16(0); } dataReader.Close(); } catch (OdbcException ex) { error = ex.Message; } } return(id); }
protected void bteliminar_Click(object sender, EventArgs e) { OdbcConnection con = conectarBD(); try { if (con != null) { String var1 = txIdElimina.Text; String query = "delete from juega where idUsuario= '" + Session["cu"].ToString() + "' and idReta=" + var1 + ";"; OdbcCommand cmd = new OdbcCommand(query, con); cmd.ExecuteNonQuery(); String qu = "select numParticipantes from reta where idReta=" + var1 + ""; OdbcCommand cmd2 = new OdbcCommand(qu, con); OdbcDataReader rd = cmd2.ExecuteReader(); if (rd.Read()) { int numP = rd.GetInt16(0) - 1; String query1 = "update reta set numParticipantes = " + numP + " where idReta= " + var1 + ";"; OdbcCommand cmd1 = new OdbcCommand(query1, con); cmd1.ExecuteNonQuery(); } con.Close(); } } catch (Exception ex) { con = null; lbAux.Text = "error" + ex; } }
public MemberInfo getMember(int id) { MemberInfo setMemberInfo = new MemberInfo(); OdbcParameter parm = new OdbcParameter(PARM_ID, OdbcType.Int); parm.Value = id; OdbcCommand cmd = new OdbcCommand("{call " + SP_SEL_MEMBER_BY_ID + "(?)}"); cmd.Parameters.Add(parm); cmd.CommandType = CommandType.StoredProcedure; using (OdbcDataReader rdr = SqlHelper.ExecuteReader(cmd, SqlHelper.USABConnectionString)) { if (rdr.Read()) { setMemberInfo.member_id = rdr.GetInt16(0); setMemberInfo.first_name = rdr.IsDBNull(1) ? string.Empty : rdr.GetString(1); setMemberInfo.last_name = rdr.IsDBNull(2) ? string.Empty : rdr.GetString(2); setMemberInfo.middle_name = rdr.IsDBNull(3) ? string.Empty : rdr.GetString(3); setMemberInfo.email = rdr.IsDBNull(4) ? string.Empty : rdr.GetString(4); setMemberInfo.role = rdr.IsDBNull(5) ? string.Empty : rdr.GetString(5); setMemberInfo.status = rdr.IsDBNull(6) ? string.Empty : rdr.GetString(6); setMemberInfo.address1 = rdr.IsDBNull(7) ? string.Empty : rdr.GetString(7); setMemberInfo.address2 = rdr.IsDBNull(8) ? string.Empty : rdr.GetString(8); setMemberInfo.city = rdr.IsDBNull(9) ? string.Empty : rdr.GetString(9); setMemberInfo.state = rdr.IsDBNull(10) ? string.Empty : rdr.GetString(10); setMemberInfo.zip = rdr.IsDBNull(11) ? string.Empty : rdr.GetString(11); setMemberInfo.birthdate = rdr.IsDBNull(12) ? string.Empty : rdr.GetString(12); } else { setMemberInfo.member_id = 0; setMemberInfo.first_name = string.Empty; setMemberInfo.last_name = string.Empty; setMemberInfo.middle_name = string.Empty; setMemberInfo.email = string.Empty; setMemberInfo.role = string.Empty; setMemberInfo.status = string.Empty; setMemberInfo.address1 = string.Empty; setMemberInfo.address2 = string.Empty; setMemberInfo.city = string.Empty; setMemberInfo.state = string.Empty; setMemberInfo.zip = string.Empty; setMemberInfo.birthdate = string.Empty; } } return(setMemberInfo); }
/// <summary> /// Returns a list of achievements that are of the specified categories. 27/11/15 /// </summary> public static List <Achievement> GetAchievements(List <string> categories) { // Create a list to store the returned achievements List <Achievement> achievements = new List <Achievement>(); // Get all achievements where the category is... string query = "SELECT * FROM `" + achievementTable + "` WHERE `Category` IN ("; // ..any of the categories specified. foreach (string x in categories) { query = (query + '"' + x + '"' + ","); } // Remove the succeeding comma that is added due to the previous foreach loop, // and finish the query with a bracket. query = query.Remove(query.Length - 1); query = query + ")"; if (connectionOpen()) { // Create a database command from the query and existing connection. OdbcCommand cmd = new OdbcCommand(query, connection); try { // Execute the command and open a reader. OdbcDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) // Read the next record. { // Get the id first, and check to make sure it is something. int id = dataReader.GetInt16(0); if (id != 0) { // Adds the achievement that is read from the database to the // list of achievements that is to be returned. achievements.Add(new Achievement(id, dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetString(4), dataReader.GetInt16(5), dataReader.GetDateTime(6), dataReader.GetBoolean(7))); } } dataReader.Close(); } catch (OdbcException ex) { // Displays an error if something bad occurs while executing the command error = ex.Message; } } return(achievements); }
public void obteneridmarca() { //OBTENIENDO ID DE CATALOGO DE PRECIOS string scad3 = "SELECT id_marca from marca where nombre_marca='" + cbo_marca.Text + "'"; OdbcCommand mcd3 = new OdbcCommand(scad3, Conexion.ObtenerConexion()); OdbcDataReader mdr3 = mcd3.ExecuteReader(); while (mdr3.Read()) { codmarca = mdr3.GetInt16(0); } }
public void obtenerid() { //OBTENIENDO ID DE CATALOGO DE PRECIOS string scad2 = "SELECT id_tprecio_pk from tipo_precio where tipo='" + cbo_catalogo.Text + "'"; OdbcCommand mcd2 = new OdbcCommand(scad2, Conexion.ObtenerConexion()); OdbcDataReader mdr2 = mcd2.ExecuteReader(); while (mdr2.Read()) { codtipo = mdr2.GetInt16(0); } }
public void obteneridcat() { //OBTENIENDO ID DE CATALOGO DE PRECIOS string scad4 = "SELECT id from categoria where nombre='" + cbo_categoria.Text + "'"; OdbcCommand mcd4 = new OdbcCommand(scad4, Conexion.ObtenerConexion()); OdbcDataReader mdr4 = mcd4.ExecuteReader(); while (mdr4.Read()) { codcategoria = mdr4.GetInt16(0); } }
//Esta funcion sirve para obtener el codigo siguiente cuando se selecciona una cuenta del treeview public int funcInsertar(int Codigo) { string Sql = "SELECT MAX( PK_ID_CUENTA_CONTABLE) FROM CUENTA_CONTABLE WHERE PK_ID_CUENTA_CONTABLE LIKE '" + Codigo + "%';"; try { OdbcCommand Command = new OdbcCommand(Sql, Con.conexion()); OdbcDataReader Reader = Command.ExecuteReader(); if (Reader.Read()) { Codigo = Reader.GetInt16(0); } } catch (Exception Ex) { Console.WriteLine(Ex.Message.ToString() + " \nError en asignarCombo, revise los parametros \n -\n -"); } return(Codigo); }
public static ArrayList FindOrderDetailsByOrderID(int orderID) { ArrayList orderDetails = new ArrayList(); string connectionString = DataUtilities.ConnectionString; if ((connectionString != null) && (connectionString.Length > 0)) { try { OdbcConnection dataConnection = new OdbcConnection(); dataConnection.ConnectionString = connectionString; dataConnection.Open(); OdbcCommand dataCommand = new OdbcCommand(); dataCommand.Connection = dataConnection; // Build Command String StringBuilder commandText = new StringBuilder("SELECT * FROM [Orders Details] WHERE OrdersID = "); commandText.Append(orderID); dataCommand.CommandText = commandText.ToString(); OdbcDataReader dataReader = dataCommand.ExecuteReader(); while (dataReader.Read()) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderID = dataReader.GetInt32(0); orderDetail.ProductID = dataReader.GetInt32(1); orderDetail.UnitPrice = dataReader.GetDecimal(2); orderDetail.QuantityOrdered = dataReader.GetInt16(3); orderDetail.Discount = dataReader.GetFloat(4); orderDetails.Add(orderDetail); } dataConnection.Close(); } catch (Exception e) { Console.WriteLine("error: " + e.Message); } } return(orderDetails); }
public static List <ExpedienteMVL> Listar(Int32 expediente) { OdbcConnection conexion = new OdbcConnection(NegocioBase.getConnectionString()); OdbcParameter parametro = new OdbcParameter(); parametro.ParameterName = "_idExpediente"; parametro.Value = expediente; parametro.OdbcType = OdbcType.Int; OdbcDataAdapter dataAdapter = new OdbcDataAdapter("Call SP_TraerExpedientesMVL(?)", conexion); dataAdapter.SelectCommand.Parameters.Add(parametro); conexion.Open(); List <ExpedienteMVL> listaExpedienteMVL = new List <ExpedienteMVL>(); try { OdbcDataReader drExpedienteMVL = dataAdapter.SelectCommand.ExecuteReader(); while (drExpedienteMVL.Read()) { ExpedienteMVL tmp = new ExpedienteMVL(); tmp.idExpediente = drExpedienteMVL.GetInt32(0); tmp.idMovimiento = drExpedienteMVL.GetByte(1); tmp.idMovimientoRecepcion = drExpedienteMVL.GetByte(2); tmp.idMovimientoDevolucion = drExpedienteMVL.GetByte(3); tmp.codigoExpedienteMVL = drExpedienteMVL.GetString(4); tmp.numeroExpedienteMVL = drExpedienteMVL.GetString(5); tmp.anioExpediente = drExpedienteMVL.GetInt16(6); listaExpedienteMVL.Add(tmp); } return(listaExpedienteMVL); } catch { throw; } finally { if (conexion.State == ConnectionState.Open) { conexion.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { OdbcConnection miConexion = conectarBD(); if (miConexion != null) { try { //Primero llenamos los eventos String query = String.Format("SELECT TOP (10) Deporte.nombre as Deporte, CAST(Evento.fecha as VARCHAR) as Fecha, CAST(Evento.hora as VARCHAR(5)) as Hora, Evento.descripcion as Descripción FROM Evento, Deporte WHERE Evento.fecha >= '{0}' AND Evento.idDep = Deporte.idDep", DateTime.Now.ToString("yyyy/MM/dd")); OdbcCommand cmd = new OdbcCommand(query, miConexion); OdbcDataReader rd = cmd.ExecuteReader(); proximosEventosView.DataSource = rd; proximosEventosView.DataBind(); //Para el dropdown list de eventos query = String.Format("SELECT TOP(10) Evento.idEvento, Deporte.nombre, CAST(Evento.fecha as VARCHAR) as Fecha FROM Evento, Deporte WHERE Evento.fecha >= '{0}' AND Evento.idDep = Deporte.idDep", DateTime.Now.ToString("yyyy/MM/dd")); cmd = new OdbcCommand(query, miConexion); rd = cmd.ExecuteReader(); ListItem row; String texto; eventosList.Items.Clear(); while (rd.Read()) { row = new ListItem(); texto = rd.GetString(1) + " del día: " + rd.GetDate(2).ToString("dd/MM/yyyy"); row.Text = texto; row.Value = rd.GetInt16(0).ToString(); eventosList.Items.Add(row); } //Llenamos los Equipos query = "SELECT Equipo.nombre as Equipo, Deporte.nombre as Deporte, Equipo.jugados as 'Partidos Juagdos', Equipo.ganados as 'Partidos Ganados', Equipo.perdidos as 'Partidos Perdidos' FROM Equipo, Deporte WHERE Equipo.idDep = Deporte.idDep"; cmd = new OdbcCommand(query, miConexion); rd = cmd.ExecuteReader(); equiposView.DataSource = rd; equiposView.DataBind(); //Cerramos la conexión miConexion.Close(); } catch (Exception ex) { //Por si hay errores con el odbc String tipo = "precaucion"; String script = forScripts(tipo, ex.Message.ToString()); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); } } }
private void Frm_filtroPreSeleccion_Load(object sender, EventArgs e) { OdbcDataReader mostrar = logic.ConsultaLogicaPreseleccionComparacion(IDReporte); try { while (mostrar.Read()) { valores[0] = mostrar.GetString(0); valores[1] = mostrar.GetString(1); valores[2] = mostrar.GetString(2); valores[3] = mostrar.GetString(3); valores[4] = mostrar.GetString(4); valores[5] = mostrar.GetString(5); sueldos = mostrar.GetDouble(6); } } catch (Exception err) { Console.WriteLine(err.Message); } //Clasificacion segun cualidades OdbcDataReader clasificar = logic.ConsultaSeleccionComparacionAceptados(IDReporte); try { while (clasificar.Read()) { if (valores[0] == clasificar.GetInt16(0).ToString() && valores[1] == clasificar.GetInt16(1).ToString() && valores[2] == clasificar.GetInt16(2).ToString() && valores[3] == clasificar.GetInt16(3).ToString() && valores[4] == clasificar.GetInt16(4).ToString() && valores[5] == clasificar.GetInt16(5).ToString() && sueldos == clasificar.GetDouble(6)) { Dgv_consultaAceptados.Rows.Add(clasificar.GetString(7), clasificar.GetString(8), clasificar.GetString(9), clasificar.GetInt16(0).ToString(), clasificar.GetInt16(1).ToString(), clasificar.GetInt16(2).ToString(), clasificar.GetInt16(3).ToString(), clasificar.GetInt16(4).ToString(), clasificar.GetInt16(5).ToString(), clasificar.GetDouble(6).ToString()); } else { Dgv_consultaRecha.Rows.Add(clasificar.GetString(7), clasificar.GetString(8), clasificar.GetString(9), clasificar.GetInt16(0).ToString(), clasificar.GetInt16(1).ToString(), clasificar.GetInt16(2).ToString(), clasificar.GetInt16(3).ToString(), clasificar.GetInt16(4).ToString(), clasificar.GetInt16(5).ToString(), clasificar.GetDouble(6).ToString()); } } } catch (Exception err) { Console.WriteLine(err.Message); } }
/// <summary> /// Returns a list of achievements from a list of achievement id's 01/12/15 /// </summary> public static List <Achievement> GetAchievementsFromIDs(List <int> ids) { // List of achievements to store the achievements to return List <Achievement> achievements = new List <Achievement>(); string query; OdbcCommand cmd; // For each of the returned IDs foreach (int x in ids) { // Create a query to get that achievement's data from the achievement table query = "SELECT * FROM `" + achievementTable + "` WHERE `ID`='" + x + "'"; // Create a database command from the query and existing connection cmd = new OdbcCommand(query, connection); if (connectionOpen()) { try { // Execute the command and open a reader OdbcDataReader dataReader = cmd.ExecuteReader(); // While there are more records to process... while (dataReader.Read()) { // Get the ID and make sure it is an actual achievement int id = dataReader.GetInt16(0); if (id >= 1) { // Then add the returned achievement to the achievement list achievements.Add(readAchievement(dataReader)); } } dataReader.Close(); } catch (OdbcException ex) { // Displays an error if something bad occurs while executing the command error = ex.Message; } } } return(achievements); // Return the final list of acievments. May be empty if the // query failed }
public static List <DetalleMovimiento> Listar(Int32 expediente) { OdbcConnection conexion = new OdbcConnection(NegocioBase.getConnectionString()); OdbcParameter parametro = new OdbcParameter(); parametro.ParameterName = "idexp"; parametro.Value = expediente; parametro.OdbcType = OdbcType.Int; OdbcDataAdapter dataAdapter = new OdbcDataAdapter("Call SP_TraerDetalleMovimientosPorExpediente(?)", conexion); dataAdapter.SelectCommand.Parameters.Add(parametro); conexion.Open(); List <DetalleMovimiento> listaDetalleMovimientos = new List <DetalleMovimiento>(); try { OdbcDataReader drDetalleMovimientos = dataAdapter.SelectCommand.ExecuteReader(); while (drDetalleMovimientos.Read()) { DetalleMovimiento tmp = new DetalleMovimiento(); tmp.idExpediente = drDetalleMovimientos.GetInt32(0); tmp.idMovimiento = drDetalleMovimientos.GetByte(1); tmp.nombreArchivo = drDetalleMovimientos.GetString(2); tmp.numeroResolucion = drDetalleMovimientos.GetInt16(3); tmp.idDependencia = drDetalleMovimientos.GetByte(4); listaDetalleMovimientos.Add(tmp); } return(listaDetalleMovimientos); } catch { throw; } finally { if (conexion.State == ConnectionState.Open) { conexion.Close(); } } }
public static ArrayList GetProductsByCategory(int categoryID) { ArrayList products = new ArrayList(); try { OdbcConnection dataConnection = new OdbcConnection(); dataConnection.ConnectionString = DataUtilities.ConnectionString; dataConnection.Open(); OdbcCommand dataCommand = new OdbcCommand(); dataCommand.Connection = dataConnection; // Build command string StringBuilder commandText = new StringBuilder("SELECT * FROM Products WHERE CategoryID = "); commandText.Append(categoryID); commandText.Append(" AND UnitsInStock > 0"); dataCommand.CommandText = commandText.ToString(); OdbcDataReader dataReader = dataCommand.ExecuteReader(); while (dataReader.Read()) { Product product = new Product(); product.ProductID = dataReader.GetInt32(0); product.ProductName = dataReader.GetString(1); product.CategoryID = dataReader.GetInt32(3); product.Price = dataReader.GetDecimal(5); product.Quantity = dataReader.GetInt16(6); products.Add(product); } dataConnection.Close(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } return(products); }
public int procInsertar(string tabla, string campo) { int codigo = 0; string sql = "SELECT MAX(" + campo + ") FROM " + tabla + " where estado = 1 ;"; try { OdbcCommand command = new OdbcCommand(sql, con.conexion()); OdbcDataReader reader = command.ExecuteReader(); if (reader.Read()) { codigo = reader.GetInt16(0); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString() + " \nError en asignarCombo, revise los parametros \n -" + tabla + "\n -" + campo); } codigo++; return(codigo); }
public static ArrayList SearchForProducts(string searchString) { ArrayList products = new ArrayList(); try { OdbcConnection dataConnection = new OdbcConnection(); dataConnection.ConnectionString = connectionString; dataConnection.Open(); OdbcCommand dataCommand = new OdbcCommand(); dataCommand.Connection = dataConnection; // Build command string StringBuilder commandText = new StringBuilder("SELECT * FROM Products WHERE ProductName LIKE '%"); commandText.Append(searchString); commandText.Append("%'"); dataCommand.CommandText = commandText.ToString(); OdbcDataReader dataReader = dataCommand.ExecuteReader(); while (dataReader.Read()) { Product product = new Product(); product.ProductID = dataReader.GetInt32(0); product.CategoryID = dataReader.GetInt32(3); product.ProductName = dataReader.GetString(1); product.Price = dataReader.GetDecimal(5); product.Quantity = dataReader.GetInt16(6); products.Add(product); } dataConnection.Close(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } return(products); }
protected void ddJuegos_SelectedIndexChanged(object sender, EventArgs e) { OdbcConnection miConexion = conectarBD(); if (miConexion != null) { String query = String.Format("select claveJ from juegos where nombre='{0}'", ddJuegos.SelectedValue); OdbcCommand cmd = new OdbcCommand(query, miConexion); OdbcDataReader rd = cmd.ExecuteReader(); rd.Read(); int claveJuego = rd.GetInt16(0); String query2 = String.Format("select nombre, resumen, consola, fechaLanzamiento from juegos where ClaveJ={0}", claveJuego); OdbcCommand cmd2 = new OdbcCommand(query2, miConexion); OdbcDataReader rd2 = cmd2.ExecuteReader(); gvJuegos.DataSource = rd2; gvJuegos.DataBind(); rd.Close(); rd2.Close(); } }
protected void ddJuegos_SelectedIndexChanged(object sender, EventArgs e) { OdbcConnection miConexion = conectarBD(); if (miConexion != null) { String query = String.Format("select claveJ from juegos where nombre='{0}'", ddJuegos.SelectedValue); OdbcCommand cmd = new OdbcCommand(query, miConexion); OdbcDataReader rd = cmd.ExecuteReader(); rd.Read(); int claveJuego = rd.GetInt16(0); String query2 = String.Format("select critica.contentido from critica where critica.claveC=(select claveC from escriben where escriben.ClaveU={0} and escriben.ClaveJ={1})", Session["claveUnica"].ToString(), claveJuego); OdbcCommand cmd2 = new OdbcCommand(query2, miConexion); OdbcDataReader rd2 = cmd2.ExecuteReader(); rd2.Read(); lbCritica.Text = rd2.GetString(0); rd.Close(); rd2.Close(); } }
protected void ddJuegos_SelectedIndexChanged(object sender, EventArgs e) { OdbcConnection miConexion = conectarBD(); if (miConexion != null) { int var1 = ddJuegos.SelectedIndex; String var2 = ddJuegos.SelectedValue; string query1 = "select claveJ from juegos where nombre = '" + var2 + "'"; OdbcCommand sql1 = new OdbcCommand(query1, miConexion); OdbcDataReader lector1 = sql1.ExecuteReader(); lector1.Read(); int var3 = lector1.GetInt16(0); String query2 = "select nombre, resumen, consola, fechaLanzamiento from juegos where claveJ=" + var3 + ""; OdbcCommand cmm = new OdbcCommand(query2, miConexion); OdbcDataReader dr = cmm.ExecuteReader(); gvJuegos.DataSource = dr; gvJuegos.DataBind();//Lo llena magicamente lector1.Close(); } }
public static Product GetProduct(int productID) { Product product = null; try { OdbcConnection dataConnection = new OdbcConnection(); dataConnection.ConnectionString = connectionString; dataConnection.Open(); OdbcCommand dataCommand = new OdbcCommand(); dataCommand.Connection = dataConnection; // Build command string StringBuilder commandText = new StringBuilder("SELECT * FROM Products WHERE ProductID = "); commandText.Append(productID); dataCommand.CommandText = commandText.ToString(); OdbcDataReader dataReader = dataCommand.ExecuteReader(); if (dataReader.Read()) { product = new Product(); product.ProductID = dataReader.GetInt32(0); product.ProductName = dataReader.GetString(1); product.CategoryID = dataReader.GetInt32(3); product.Price = dataReader.GetDecimal(5); product.Quantity = dataReader.GetInt16(6); } dataConnection.Close(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } return(product); }