Visual Basic.NET - buscar en Access

 
Vista:

buscar en Access

Publicado por novato (14 intervenciones) el 17/04/2008 19:28:01
Buenos dias a todos!
Dim reader As OleDbDataReader
Private Sub FindRecord()

Dim strNumeroPersonal As String
Dim strNombre As String
Dim strDesignacion As String
Dim strDepartment oAs String
Dim strLocalidad As String

If txtFind.Text = "" Then
MsgBox("Digite Datos a Buscar!")
txtFind.Focus()
Else
If (reader.Read()) Then

strNumeroPersonal =reader("NumeroPersonal").ToString()
strNombre = reader("Nombre").ToString()
strDesigantion = reader("Designacion").ToString()
strDepartment = reader("Departmento").ToString()
strLocation = reader("Localidad").ToString()

TextBox1.Text = strNumeroPersonal
TextBox2.Text = strNombre
TextBox3.Text = strDesignacion
TextBox4.Text = strDepartmento
TextBox5.Text = strLocalidad

Private Sub find_Click()
FindRecord
End Sub

Alguien que por favor me pueda dar una ayudita, pues cuando hago clic en "buscar" me da el siguiente error
NullReferenceException...: Object reference not set to an instance of object.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:buscar en Access

Publicado por Jim Miñano (44 intervenciones) el 18/04/2008 03:07:20
'Intenta con esto
Sub buscar()

Dim olecnn As New OleDb.OleDbConnection
olecnn.ConnectionString = "tu cadena de conexion"
Try
olecnn.Open()

Catch ex As OleDb.OleDbException
MsgBox(ex.ToString)
Return
End Try

Dim olecmd As New OleDb.OleDbCommand
'si es valor numero
olecmd.CommandText = String.Format("select * from tabla where campo={1}", TextBox1.Text)
'si es valor texto o fecha
olecmd.CommandText = String.Format("select * from tabla where campo'={1}'", TextBox1.Text)

'se enlaza con la conexion
olecmd.Connection = olecnn

Dim reader As OleDb.OleDbDataReader
reader = olecmd.ExecuteReader

'si sabes q solo devolvera un regitro
If reader.Read Then

End If
'----------------------------------

'esto es cuando pueden ser varios
Do While reader.Read

Loop
'-----------------------

'liverando algo derecursos
reader.Close()
olecmd.Dispose()
olecnn.Close()
olecnn.Dispose()

End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:buscar en Access

Publicado por novato (14 intervenciones) el 18/04/2008 06:02:54
Muchas gracias me sirvio es de buena orientacion y lo habia conceptuado asi
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar