Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Reader wont refresh records 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm using a data reader for basically a read only form. I have a textbox where a user would enter a number, then the reader goes out and finds that record and updates the form.

the first record returns fine but when I go to enter a different number in the textbox to go out and find another record, the form doesn't refresh with the new data. I don't get any errors so I'm assuming it found the record. why does the form refresh ?

below is my code.

any help would be appreciated.

sqlCnn = New SqlConnection(connetionString)

Try
sqlCnn.Open()
sqlCmd = New SqlCommand(sql, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
While sqlReader.Read()
Label5.Text = sqlReader("field1") & ""
Label6.Text = sqlReader("field2") & ""
Label7.Text = sqlReader("field3") & ""
Label8.Text = sqlReader("field4") & ""
End While
sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()

Catch ex As Exception
MsgBox("Error in Dataset !")

End Try

 
Does your DataReader have any records to read?

Try this:

Code:
Try
sqlCnn.Open()
sqlCmd = New SqlCommand(sql, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()[blue]
Dim b As Boolean = False[/blue]
While sqlReader.Read()[blue]
  b = True[/blue]
  Label5.Text = sqlReader("field1") & ""
  Label6.Text = sqlReader("field2") & ""
  Label7.Text = sqlReader("field3") & ""
  Label8.Text = sqlReader("field4") & ""
End While[blue]
If Not b Then
    MsgBox "No records to show"
End If[/blue]
sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()

Catch ex As Exception
MsgBox("Error in Dataset !")

End Try

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top