0% found this document useful (0 votes)
20 views

Insercion de Datos A Una Tabla: - Imports - Imports - Imports

This document discusses inserting data into a Visual Basic.NET data table. It imports SQL connection libraries and defines a SQL connection string. It includes code to fill a dataset from a database table on button click, and to insert new records into the table on another button click. The insert code defines an SQL statement with parameters and adds the parameter values from textboxes before executing the insert.

Uploaded by

Haydee Hilasaca
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Insercion de Datos A Una Tabla: - Imports - Imports - Imports

This document discusses inserting data into a Visual Basic.NET data table. It imports SQL connection libraries and defines a SQL connection string. It includes code to fill a dataset from a database table on button click, and to insert new records into the table on another button click. The insert code defines an SQL statement with parameters and adds the parameter values from textboxes before executing the insert.

Uploaded by

Haydee Hilasaca
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

INSERCION DE DATOS A UNA TABLA VISUAL BASIC.

NET

--Imports System.Data --Imports System.Data.SqlClient --Imports System.Data.SqlClient.SqlException Public Class Form1 --Private dv As New DataView -- Dim cnn As New SqlConnection( --"Data Source=COMPAQ-PC;Initial Catalog=estudiante; Integrated Security=SSPI;")

Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click 'MsgBox("conectado a base de datos") Dim da As New SqlDataAdapter("select * from talumno", cnn) Dim ds As New DataSet da.Fill(ds) dv.Table = ds.Tables(0) DataGridView2.DataSource = dv End Sub Private Sub btnInsertar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertar.Click Dim sql As String = "insert into talumno values(@codigo, @nombre,@apellido, @direccion, @telefono,@estado)" Dim cmd As New SqlCommand(sql, cnn) Try cmd.CommandType = CommandType.Text cmd.Parameters.Add("@codigo", SqlDbType.NChar, 5).Value = Me.TxtCodigo.Text

cmd.Parameters.Add("@nombre", SqlDbType.NChar, 10).Value = Me.TxtNombre.Text cmd.Parameters.Add("@apellido", SqlDbType.NChar, 10).Value = "jr. puno" cmd.Parameters.Add("@direccion", SqlDbType.Char, 1).Value = "f" cmd.Parameters.Add("@telefono", SqlDbType.DateTime).Value = "2013-0305" cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = "a" MsgBox("ola") cnn.Open() cmd.ExecuteNonQuery() MessageBox.Show("REGISTRO INSERTADO CORRECTAMENTE") Catch ex As Exception End Try End Sub

Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click Me.txtcodigo.Text = "" Me.txtnombre.Text = "" End Sub End Class

You might also like