estoy haciendo el siguiente código en c# pero me marca dos errores en varias lineas del código que dicen
El nombre txtId no existe en el conexto actual
El nombre txtNombre no existe en el contexto actual
no entiendo por qué me da esos errores, esta es la primera vez que programo en c#
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; using Mono.Security; namespace Proyecto_BasesDatos { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void cmdAgregar_Click(object sender, EventArgs e) { if (txtId.Text == "" || txtNombre.Text == "") { MessageBox.Show("Debes Introducir Valores"); } else { try { string Nombre = txtNombre.Text; int Id = Convert.ToInt16(txtId.Text); IDbConnection dbcon = new NpgsqlConnection("Server=localhost;" + "Database=Conexion;" + "User Id=Marcela;"); dbcon.Open(); IDbCommand dbcmd = dbcon.CreateCommand(); dbcmd.CommandText = "insert into Clientes values (" + Id + " , '" + Nombre + "')"; IDataReader reader = dbcmd.ExecuteReader(); dbcon.Close(); txtNombre.Text = ""; txtId.Text = ""; MessageBox.Show("Registro Guardado Correctamente"); } catch (Exception msg) { MessageBox.Show("error.......................\n\n" + msg.ToString()); } } } } }
gracias





Autor


En línea


?, en el formulário falta que agreges un control que tenga la propiedad "Text" (Por ejemplo un Textbox) con el nombre "txtId", y luego agregas otro control (otro textbox) y le cambias el nombre a: "txtNombre", puedes agregar los controles en el código o arrastrándolos desde el Designer.



