VISUAL ESTUDIO 2010 & SQL SERVER 2008
· Primeramente crea el base de datos en sql server
·
· Procedimiento Almacenado
· Codigo Fuente
Imports System.Data.SqlClient
Public Class Form1
Dim cn As New SqlConnection
Dim cadena As String = "Data Source=CRISTIAN-PC\SQLEXPRESS;Initial Catalog=matriculas;Integrated Security=True"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.ConnectionString = cadena
Dim cmd As New SqlCommand
cmd.Connection = cn
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As New DataSet
'CARGA PARA COMBOBOX
Dim cmd1 As New SqlCommand("CODIGOS1", cn)
With cmd1
.CommandType = CommandType.StoredProcedure
Dim da1 As New SqlDataAdapter(cmd1)
Dim dt1 As New DataTable
da1.Fill(dt1)
ComboBox1.DataSource = dt1
ComboBox1.DisplayMember = "COD"
End With
End Sub
'CODIGO PARA COMBOBOX
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim cmd2 As New SqlCommand("CODIGOS", cn)
TextBox1.DataBindings.Clear()
TextBox2.DataBindings.Clear()
TextBox3.DataBindings.Clear()
With cmd2
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("@xcod", ComboBox1.Text))
Dim da2 As New SqlDataAdapter(cmd2)
Dim dt2 As New DataTable
da2.Fill(dt2)
TextBox1.DataBindings.Add(New Binding("Text", dt2, "NOM"))
TextBox3.DataBindings.Add(New Binding("Text", dt2, "APE"))
TextBox2.DataBindings.Add(New Binding("Text", dt2, "DIR"))
End With
End Sub
End Class
0 comentarios:
Publicar un comentario
Dudas y sugerencias aqui