This document contains C# code for inserting buttons that perform database operations. It defines functions for a search button that queries a database and displays results, an insert button that adds a new record to the database, an update button that modifies an existing record, and a delete button that removes a record. The code connects to an Access database, builds SQL queries, executes them, and displays messages on the results.
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Insert buttons in C# - Add, update, delete records
1. Insertarbotones en c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClaseMiercoles29mayo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void butBuscar_Click(object sender, EventArgs e)
{
string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:basevendedores.accdb";
//Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:UsersCoodinacionDocumentsDatabase2.accdb;Persist Security Info=False";
string ssql = "Select * From Tabla1 where Idv =" + Int32.Parse(textId.Text);
OleDbDataAdapter da = new OleDbDataAdapter(ssql, conexion);
2. OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
int fila1 = 0;
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[fila1];
textNombre.Text = dr["vNombre"].ToString();
OleDbDataAdapter da2 = new OleDbDataAdapter("select * from Tabla1", conexion);
OleDbCommandBuilder cb2 = new OleDbCommandBuilder(da2);
//DataTable dt2 = new DataTable();
DataSet dsDatos = new DataSet();
da2.Fill(dsDatos, "Vendedores");
this.dataGridView1.DataMember = "Vendedores";
this.dataGridView1.DataSource = dsDatos;
}
else
{
textNombre.Text = "";
MessageBox.Show("No hay datos");
}
}