INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER

18,625 views
18,089 views

Published on

INSERCION DE REGISTROS DESDE VISUAL.NET A LA BD DE SQL SERVER

Published in: Education, Technology
3 Comments
6 Likes
Statistics
Notes
No Downloads
Views
Total views
18,625
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
1,184
Comments
3
Likes
6
Embeds 0
No embeds

No notes for slide

INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER

  1. 1. INSERCION DE DATOS A UNA TABLA<br />VISUAL BASIC.NET<br />CREATE DATABASE EJERCICIO<br />USE EJERCICIO<br />CREATE TABLE PRUEBA<br />(CODIGO VARCHAR (5), <br />NOMBRE NVARCHAR (25), <br />APELLIDO NVARCHAR(25),<br />DIRECCION NVARCHAR(25), <br />TELEFONO FLOAT(53))<br />SELECT * FROM PRUEBA<br />CREAR UN MODULO<br />Imports System.Data.sqlclient<br />Module CONEXION<br /> Public cn As New SqlConnection(" server = (local); database = ejercicio; user id = sa; password=123" )<br />End Module<br />Imports System.Data.sqlclient<br />Public Class Form1<br /> Dim da As SqlDataAdapter<br /> Dim ds As DataSet<br /> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br /> End Sub<br /> Private Sub btngrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngrabar.Click<br /> Dim sql As String = " insert into PRUEBA values(@codigo, @nombre,@apellido, @direccion, @telefono)" <br /> Dim cmd As New SqlCommand(sql, cn)<br /> Try<br /> cmd.CommandType = CommandType.Text<br /> cmd.Parameters.Add(" @codigo" , SqlDbType.VarChar, 5).Value = Me.txtcodigo.Text<br /> cmd.Parameters.Add(" @nombre" , SqlDbType.NVarChar, 25).Value = Me.txtnombres.Text<br /> cmd.Parameters.Add(" @apellido" , SqlDbType.NVarChar, 25).Value = Me.txtapellidos.Text<br /> cmd.Parameters.Add(" @direccion" , SqlDbType.NVarChar, 20).Value = Me.txtdirecion.Text<br /> cmd.Parameters.Add(" @telefono" , SqlDbType.Float, 53).Value = Me.txttelefono.Text<br /> CN.Open()<br /> cmd.ExecuteNonQuery()<br /> MessageBox.Show(" REGISTRO INSERTADO CORRECTAMENTE" )<br /> Catch ex As Exception<br /> End Try<br /> End Sub<br /> Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click<br /> Me.txtcodigo.Text = " " <br /> Me.txtnombres.Text = " " <br /> Me.txtapellidos.Text = " " <br /> Me.txtdirecion.Text = " " <br /> Me.txttelefono.Text = " " <br /> End Sub<br />End Class<br />

×