0% found this document useful (0 votes)
24 views6 pages

Presentación 1

This document discusses connecting to a SQL database and performing CRUD operations from a .NET application. It defines a connection string to a SQL Server database and uses OleDb to execute queries and populate a dataset. It includes code to open the connection, fill the dataset, insert a new row, and update the database. It also defines a class to clear fields in a form's controls.

Uploaded by

Daryl Worrell
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Presentación 1

This document discusses connecting to a SQL database and performing CRUD operations from a .NET application. It defines a connection string to a SQL Server database and uses OleDb to execute queries and populate a dataset. It includes code to open the connection, fill the dataset, insert a new row, and update the database. It also defines a class to clear fields in a form's controls.

Uploaded by

Daryl Worrell
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Conexin a Sql

Public Class Borrar Public Sub Limpiar_campos(ByVal FORMA As System.Windows.Forms.Control)

Dim CTR1 As System.Windows.Forms.Control For Each CTR1 In FORMA.Controls


If (CTR1.GetType() Is GetType(TextBox)) Then CTR1.Text = "" End If If (CTR1.GetType() Is GetType(ComboBox)) Then CTR1.Text = "" End If Next End Sub End Class

Codigo del formulario Imports System Public Class Form1 Inherits System.Windows.Forms.Form ' Dim strcon As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Micro;Local Souurce=(local)" Dim strcon As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CLIENTES;Data Source=FELIXPC\SQLEXPRESS;Initial Catalog=NORTHWIND;Integrated Security=True"

Dim sql As String = "Select * from Clientes" Dim con As New Data.OleDb.OleDbConnection(strcon) Dim adaptador As New Data.OleDb.OleDbDataAdapter(sql, con) Dim dset As New DataSet Dim bulder As New Data.OleDb.OleDbCommandBuilder(adaptador) 'Objeto sumamente necesario para insertar, modificar, eliminar

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try con.Open() adaptador.Fill(dset, "Clientes") Catch ex As Exception MessageBox.Show("Fallo la conexion ", ex.Message)

End Try

If con.State = ConnectionState.Open Then Try ' VALIDAR DATOS ANTES DE GRABAR Dim nuevo As DataRow nuevo = Me.dset.Tables("Clientes").NewRow nuevo("idcliente") = Val(Me.txtID.Text) nuevo("compaia") = Me.txtCompany.Text nuevo("nombre") = Me.txtNombre.Text nuevo("telefono") = Val(Me.txtTel.Text) ' ADIR REGISTRO A LA TABLA Y ACTULIZARLA Me.dset.Tables("Clientes").Rows.Add(nuevo) Me.adaptador.Update(Me.dset, "Clientes") MessageBox.Show("Registro insertado") Dim CONTROL As New Control Catch ex As Exception End Try End If con.Close() End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim miclase As New BORRAR miclase.Limpiar_campos(Me) End Sub -----------------------------------------End Class

You might also like