Entradas

Mostrando entradas de octubre 7, 2010

SQLDataReader

Imports System.Data.SqlClient
Public Class Form1
Dim cn As New SqlConnection("server=(Local); database=ejemplo; integrated security=true")

Private Sub btnbuscar_Click(ByVal sender...)
Dim cmd As New SqlCommand("Select * from Alumnos where idalumno=@cod", cn)
cmd.Parameters.AddWithValue("@cod", txtcod.Text)
Dim dr As SqlDataReader
cn.Open()
dr = cmd.ExecuteReader
If dr.Read Then
    txtnom.Text = dr.GetString(1).ToString
    txtape.Text = dr.GetString(2).ToString
Else
    MsgBox("El Codigo " & txtcod.Text & " ingresado no existe!", MsgBoxStyle.Critical, "Informando")
    txtcod.Focus()
End If
dr.Close()
cn.Close()

End Sub
End Class