SlideShare a Scribd company logo
1 of 4
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);
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");
}
}
private void buttInsertar_Click(object sender, EventArgs e)
{
string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:basevendedores.accdb";
string vSql = "Insert into Tabla1 (idv, VNombre) values ( " + Int32.Parse(textId.Text) + " ,'" +
textNombre.Text + "')";
OleDbConnection miConeccion = new OleDbConnection(conexion);
OleDbCommand miComando = new OleDbCommand(vSql);
miComando.Connection = miConeccion;
miConeccion.Open();
miComando.ExecuteNonQuery();
miComando.Connection.Close();
MessageBox.Show("Alumo Agregado exitosamente");
}
private void buttActualizar_Click(object sender, EventArgs e)
{
string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:basevendedores.accdb";
string vSql = "Update Tabla1 set VNOmbre = '" + textNombre.Text + "'" + " where Idv =" +
Int32.Parse(textId.Text);
OleDbConnection miConeccion = new OleDbConnection(conexion);
OleDbCommand miComando = new OleDbCommand(vSql);
miComando.Connection = miConeccion;
miConeccion.Open();
miComando.ExecuteNonQuery();
miComando.Connection.Close();
MessageBox.Show("Alumo Actualizado exitosamente");
}
private void buttEliminar_Click(object sender, EventArgs e)
{
string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:basevendedores.accdb";
string vSql = "Delete from Tabla1 where Idv =" + Int32.Parse(textId.Text);
OleDbConnection miConeccion = new OleDbConnection(conexion);
OleDbCommand miComando = new OleDbCommand(vSql);
miComando.Connection = miConeccion;
miConeccion.Open();
miComando.ExecuteNonQuery();
miComando.Connection.Close();
MessageBox.Show("Alumo Eliminado exitosamente");
}
}
}

More Related Content

What's hot

Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentationmrmean
 
20131004 - Sq lite sample by Jax
20131004 - Sq lite sample by Jax20131004 - Sq lite sample by Jax
20131004 - Sq lite sample by JaxLearningTech
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Testing with Containers
Testing with ContainersTesting with Containers
Testing with ContainersRomain Baugue
 
Dot net technology
Dot net technologyDot net technology
Dot net technologyMilanMiyani1
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaBabacar NIANG
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4soelinn
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentVladimir Medina
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint dataVladimir Medina
 
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersCocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersStijn Willems
 
Contact Book Version 1.0
Contact Book Version 1.0Contact Book Version 1.0
Contact Book Version 1.0Salman Mushtaq
 
ObjectCreatorUserGuide
ObjectCreatorUserGuideObjectCreatorUserGuide
ObjectCreatorUserGuideRoger Robins
 

What's hot (20)

Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentation
 
20131004 - Sq lite sample by Jax
20131004 - Sq lite sample by Jax20131004 - Sq lite sample by Jax
20131004 - Sq lite sample by Jax
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
NestJS
NestJSNestJS
NestJS
 
Testing with Containers
Testing with ContainersTesting with Containers
Testing with Containers
 
Examplecode
ExamplecodeExamplecode
Examplecode
 
SQLite with UWP
SQLite with UWPSQLite with UWP
SQLite with UWP
 
Dot net technology
Dot net technologyDot net technology
Dot net technology
 
Html web sql database
Html web sql databaseHtml web sql database
Html web sql database
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4
 
Introduction to ASP.Net Viewstate
Introduction to ASP.Net ViewstateIntroduction to ASP.Net Viewstate
Introduction to ASP.Net Viewstate
 
Sql-Injection
Sql-InjectionSql-Injection
Sql-Injection
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersCocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollers
 
Contact Book Version 1.0
Contact Book Version 1.0Contact Book Version 1.0
Contact Book Version 1.0
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
iOS testing
iOS testingiOS testing
iOS testing
 
ObjectCreatorUserGuide
ObjectCreatorUserGuideObjectCreatorUserGuide
ObjectCreatorUserGuide
 

Similar to Insert buttons in C# - Add, update, delete records

PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
in order to save data from access database and search from it in c# .pdf
in order to save data from access database and search from it in c# .pdfin order to save data from access database and search from it in c# .pdf
in order to save data from access database and search from it in c# .pdfkalerottnerheissst52
 
New text document
New text documentNew text document
New text documentTam Ngo
 
Vb database connections
Vb database connectionsVb database connections
Vb database connectionsTharsikan
 
Program.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdfProgram.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdfanandf0099
 
201003 - Abdullah.pdf
201003 - Abdullah.pdf201003 - Abdullah.pdf
201003 - Abdullah.pdfAbdullah20897
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
3-ADO.NET.pdf
3-ADO.NET.pdf3-ADO.NET.pdf
3-ADO.NET.pdfManalAg
 
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentationCsmr2012 bettenburg presentation
Csmr2012 bettenburg presentationSAIL_QU
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY GOKUL SREE
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingChema Alonso
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursorsinfo_zybotech
 

Similar to Insert buttons in C# - Add, update, delete records (20)

PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
in order to save data from access database and search from it in c# .pdf
in order to save data from access database and search from it in c# .pdfin order to save data from access database and search from it in c# .pdf
in order to save data from access database and search from it in c# .pdf
 
New text document
New text documentNew text document
New text document
 
Vb database connections
Vb database connectionsVb database connections
Vb database connections
 
Soa lab
Soa lab   Soa lab
Soa lab
 
37c
37c37c
37c
 
Program.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdfProgram.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdf
 
menu strip - visual basic
menu strip - visual basicmenu strip - visual basic
menu strip - visual basic
 
201003 - Abdullah.pdf
201003 - Abdullah.pdf201003 - Abdullah.pdf
201003 - Abdullah.pdf
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
3-ADO.NET.pdf
3-ADO.NET.pdf3-ADO.NET.pdf
3-ADO.NET.pdf
 
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentationCsmr2012 bettenburg presentation
Csmr2012 bettenburg presentation
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
 
Database c# connetion
Database c# connetionDatabase c# connetion
Database c# connetion
 
Ditec esoft C# project
Ditec esoft C# project Ditec esoft C# project
Ditec esoft C# project
 
Ditec esoft C# project
Ditec esoft C# projectDitec esoft C# project
Ditec esoft C# project
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 

More from Armando Gonzalez

Construccion de un ared lan
Construccion de un ared lanConstruccion de un ared lan
Construccion de un ared lanArmando Gonzalez
 
Compartir unudad de cd, impresora , carpeta
Compartir unudad de cd, impresora , carpetaCompartir unudad de cd, impresora , carpeta
Compartir unudad de cd, impresora , carpetaArmando Gonzalez
 
Cresacion de una red lan Packet Tracer
Cresacion de una red lan Packet TracerCresacion de una red lan Packet Tracer
Cresacion de una red lan Packet TracerArmando Gonzalez
 

More from Armando Gonzalez (6)

Insertarbotones en c
Insertarbotones en cInsertarbotones en c
Insertarbotones en c
 
Construccion de un ared lan
Construccion de un ared lanConstruccion de un ared lan
Construccion de un ared lan
 
Reporte network magic
Reporte network magicReporte network magic
Reporte network magic
 
Compartir unudad de cd, impresora , carpeta
Compartir unudad de cd, impresora , carpetaCompartir unudad de cd, impresora , carpeta
Compartir unudad de cd, impresora , carpeta
 
Red servidor
Red servidorRed servidor
Red servidor
 
Cresacion de una red lan Packet Tracer
Cresacion de una red lan Packet TracerCresacion de una red lan Packet Tracer
Cresacion de una red lan Packet Tracer
 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
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"); } }
  • 3. private void buttInsertar_Click(object sender, EventArgs e) { string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:basevendedores.accdb"; string vSql = "Insert into Tabla1 (idv, VNombre) values ( " + Int32.Parse(textId.Text) + " ,'" + textNombre.Text + "')"; OleDbConnection miConeccion = new OleDbConnection(conexion); OleDbCommand miComando = new OleDbCommand(vSql); miComando.Connection = miConeccion; miConeccion.Open(); miComando.ExecuteNonQuery(); miComando.Connection.Close(); MessageBox.Show("Alumo Agregado exitosamente"); } private void buttActualizar_Click(object sender, EventArgs e) { string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:basevendedores.accdb"; string vSql = "Update Tabla1 set VNOmbre = '" + textNombre.Text + "'" + " where Idv =" + Int32.Parse(textId.Text); OleDbConnection miConeccion = new OleDbConnection(conexion); OleDbCommand miComando = new OleDbCommand(vSql); miComando.Connection = miConeccion; miConeccion.Open(); miComando.ExecuteNonQuery(); miComando.Connection.Close(); MessageBox.Show("Alumo Actualizado exitosamente"); }
  • 4. private void buttEliminar_Click(object sender, EventArgs e) { string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:basevendedores.accdb"; string vSql = "Delete from Tabla1 where Idv =" + Int32.Parse(textId.Text); OleDbConnection miConeccion = new OleDbConnection(conexion); OleDbCommand miComando = new OleDbCommand(vSql); miComando.Connection = miConeccion; miConeccion.Open(); miComando.ExecuteNonQuery(); miComando.Connection.Close(); MessageBox.Show("Alumo Eliminado exitosamente"); } } }