Este foirmulario es una parte de un proyecto q toy haciendo: pero tengo un problema, teoricamente cada vez q escriba una letra me salen todos los registros q en el campo nombre contienen esa letra no importa la posicion, y mientras aumento se reduce la lista, algo parecido como cuando en Winamp presionas J y te sale otra ventana donde vas escribiendo y te sale la lista de todas las canciones q contienen esa cadena, el codigo es este, aunq no me funfiona a ver si alguien me pueda decir por que u otro metodo para hacerlo, gracias;
Imports System.Data.SqlClient
Public Class busqueda
Inherits System.Windows.Forms.Form
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents lstnombre As System.Windows.Forms.ListBox
Friend WithEvents listapellido As System.Windows.Forms.ListBox
Friend WithEvents txtname As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(busqueda))
Me.lstnombre = New System.Windows.Forms.ListBox
Me.listapellido = New System.Windows.Forms.ListBox
Me.txtname = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'lstnombre
'
Me.lstnombre.Location = New System.Drawing.Point(8, 64)
Me.lstnombre.Name = "lstnombre"
Me.lstnombre.Size = New System.Drawing.Size(140, 95)
Me.lstnombre.TabIndex = 0
'
'listapellido
'
Me.listapellido.Location = New System.Drawing.Point(152, 64)
Me.listapellido.Name = "listapellido"
Me.listapellido.Size = New System.Drawing.Size(140, 95)
Me.listapellido.TabIndex = 1
'
'txtname
'
Me.txtname.Location = New System.Drawing.Point(120, 8)
Me.txtname.Name = "txtname"
Me.txtname.Size = New System.Drawing.Size(112, 20)
Me.txtname.TabIndex = 2
Me.txtname.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 3
Me.Label1.Text = "Ingrese el nombre:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(144, 18)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Nombres"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(152, 48)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(144, 18)
Me.Label3.TabIndex = 5
Me.Label3.Text = "Apellidos"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Button1
'
Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
Me.Button1.Location = New System.Drawing.Point(256, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(32, 23)
Me.Button1.TabIndex = 6
'
'busqueda
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(304, 166)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.listapellido)
Me.Controls.Add(Me.lstnombre)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtname)
Me.Name = "busqueda"
Me.Text = "busqueda"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtname.TextChanged
Try
listapellido.Items.Clear()
lstnombre.Items.Clear()
Dim conexion As New SqlConnection("data source=(local);initial catalog=jovenes;user id=sa;password=")
Dim cad As String = "select apellidos,nombre from Jovenes where nombre like '% " & txtname.Text.Trim & " %' "
Dim comando As New SqlCommand(cad, conexion)
Dim lector As SqlDataReader
conexion.Open()
lector = comando.ExecuteReader
While lector.Read = True
listapellido.Items.Add(lector(0))
lstnombre.Items.Add(lector(1))
Label1.Text = lector(0)
End While
conexion.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub busqueda_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class