Código
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Npgsql; namespace Agencia_de_Viajes { public partial class Form5 : Form { public Form5() { InitializeComponent(); } private void irMenu_Click(object sender, EventArgs e) { this.Visible = false; menu.Visible = true; } private void cmdAgregar_Click(object sender, EventArgs e) { if (txtNumeroCuenta.Text == "" || txtDescripcion.Text == "" || txtIdCliente.Text == "") { MessageBox.Show("DEBES INTRODUCIR VALORES..."); } else { int NUMERO = Convert.ToInt16(txtNumeroCuenta.Text); string DESCRIPCION = txtDescripcion.Text; int ID = Convert.ToInt16(txtIdCliente.Text); string FECHA = dateTimePicker1.Value.ToString("yyyy-MM-dd"); try { IDbConnection dbcon = new NpgsqlConnection("Server = localhost;" + "Database = Facturas;" + "User ID = marcela;"); dbcon.Open(); IDbCommand dbcmd = dbcon.CreateCommand(); dbcmd.CommandText = "insert into Cuentas_extras values(" + NUMERO + ",'" + DESCRIPCION + "'," + ID + ",'" + FECHA + "');"; IDataReader reader = dbcmd.ExecuteReader(); dbcon.Close(); txtNumeroCuenta.Text = ""; txtDescripcion.Text = ""; txtIdCliente.Text = ""; MessageBox.Show("Registro Guardado correctamente"); } catch (Exception msg) { MessageBox.Show("error.....\n\n" + msg.ToString()); } } } private void cmdMostrar_Click(object sender, EventArgs e) { try { NpgsqlConnection conexion = new NpgsqlConnection("Server = localhost; " + "Database = Facturas;" + "User ID = marcela;"); adaptador.Fill(tablamemoria); dtaCuentasExtras.DataSource = tablamemoria.DefaultView; } catch (Exception msg) { MessageBox.Show("Error......\n\n" + msg.ToString()); } } int n; private void cmdBuscar_Click(object sender, EventArgs e) { if (txtBuscado.Text == "") { MessageBox.Show("DEBES INTRODUCIR EL NUMERO DE CUENTA A BUSCAR..."); txtBuscado.Focus(); } else { try { int band = 0; IDbConnection dbcon = new NpgsqlConnection("Server = localhost;" + "Database = Facturas;" + "User ID = marcela;"); dbcon.Open(); IDbCommand dbcmd = dbcon.CreateCommand(); n = Convert.ToInt32(txtBuscado.Text); dbcmd.CommandText = "select * from cuentas_extras where numero_cuenta =" + n + ""; IDataReader reader = dbcmd.ExecuteReader(); if (reader.Read()) { txtDescripcion.Text = reader.GetString(reader.GetOrdinal("descripcion")); txtIdCliente.Text = Convert.ToString(reader.GetInt32(reader.GetOrdinal("id_cliente"))); txtNumeroCuenta.Text = Convert.ToString(reader.GetInt32(reader.GetOrdinal("numero_cuenta"))); dateTimePicker1.Text = reader.GetString(reader.GetOrdinal("fecha")); band = 1; txtBuscado.Text = ""; } dbcon.Close(); if (band == 0) { txtBuscado.Text = ""; txtDescripcion.Text = ""; txtIdCliente.Text = ""; txtNumeroCuenta.Text = ""; MessageBox.Show("Numero de cuenta no encontrado"); } } catch (Exception msg) { MessageBox.Show(msg.ToString()); } } } } }
gracias