Ver Mensaje Individual
  #12 (permalink)  
Antiguo 03/08/2011, 11:41
sqyandmy
 
Fecha de Ingreso: enero-2011
Ubicación: Guadalajara, Jalisco
Mensajes: 9
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: Detectar numero o caracter en un textbox

Esta función recibe como parámetros el textbox, la sentencia sql y las opciones de búsquedas;
lo único que tienes que recordar es que en la sentencia sql tendrás que poner "<FILTRAR>" en donde deseas que se busque el codigo; por ejemplo si tienes un id y un código seria algo así:
"SELECT idproducto,codigo FROM tblproductos WHERE codigo LIKE <FILTRAR> limit 1;" como parámetro sql.
espero que eso es lo que buscas:


Function fAutoCompletadoTextBox(ByRef text As TextBox, ByVal sql As String, Optional ByVal BuscarEn As String = "INICIO") As Integer

Dim tmpIdentificador As Integer = 0

If text.Text.Length > 0 Then

Dim primero As String = "%"
Dim segundo As String = "%"

Const ENMEDIO As String = "ENMEDIO"
Const INICIO As String = "INICIO"
Const IGUAL As String = "IGUAL"

Dim sqlike = ""

Dim autotext As String = ""
Dim indexVal As Integer = 0

If AutoSql <> "" Then

If BuscarEn = IGUAL Then
primero = ""
segundo = ""
ElseIf BuscarEn = INICIO Then
primero = ""
segundo = "%"
End If

sqlike = " '" & primero & cadenaOriginal & segundo & "' "
sql = sql.Replace("<FILTRAR>", sqlike)
gLector = gClaseDatos.fEjecutaQuerySQL(sql)
Try

While gLector.Read()
tmpIdentificador = gLector.GetInt32(0)
autotext = gLector.GetString(1).ToUpper
Exit While
End While

Catch ex As Exception
tmpIdentificador = 0
End Try

gClaseDatos.fCierraConexiones()
End If

If tmpIdentificador > 0 Then

indexVal = autotext.IndexOf(cadenaOriginal, 0, StringComparison.CurrentCultureIgnoreCase)
Try
autotext = autotext.Substring(indexVal + cadenaOriginal.Length)
text.AppendText(autotext)
Catch
End Try

indexVal = cadenaOriginal.Length
text.Select(indexVal, autotext.Length)

If Not text.BackColor = Color.LightBlue Then
text.BackColor = Color.LightBlue
End If
Else
If Not text.BackColor = Color.LightSalmon Then
If txtBuscar.Text.Length > 0 Then
text.BackColor = Color.LightSalmon
End If
End If

End If
Else
If Not text.BackColor = Color.LightBlue Then
text.BackColor = Color.LightBlue
End If
End If

Return tmpIdentificador

End Function