Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to get a record by using the Id from the client but it keeps telling me no record found

here is the code:

VB
Private Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click
       Try

           Dim str As String ' str = string "string"
           str = "SELECT * FROM tblClientes WHERE (NumId = " & txtNumID.Text & ")"
           'Instruccion de SQL
           Dim comando As OleDbCommand = New OleDbCommand(str, miConeccion)
           dataReader = comando.ExecuteReader
           While dataReader.Read()
               txtNombre.Text = dataReader("Nombre").ToString
               txtApe.Text = dataReader("Apellido").ToString
               txtCiudad.Text = dataReader("Ciudad").ToString
               txtNumT.Text = dataReader("Telefono").ToString
               txtSS.Text = dataReader("Seguro Social").ToString
               txtZipCode.Text = dataReader("ZipCode").ToString
           End While

       Catch ex As Exception
           'mensaje en caso de error;
           MsgBox("No se encontro la informacion")
       End Try
       miConeccion.Close()
   End Sub

I'm not used to VB most of the time I use C# and I do not know if it's a bracket thing or something else, Thank You
Posted

1 solution

If it is saying that no records are found, it is because there are no records where the NumId batch the text you typed in the text box. Check your data - both the text box content and the database.

And don't do it like that!
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.


[edit]
If what you mean is that you get the message box saying "No se encontro la informacion", then you need to look at the exception detail, either by adding it to the message box text, or by looking with the debugger - we can't give accurate advice if we don't know what it is complaining about!
[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900