I've been using data readers for some time now and have never had a problem until now. I can't figure this out.
I'm using a datareader to populate some controls. Textboxes and comboboxes. I'm typing a record number into a textbox to execute the reader below. everything gets populated correctly except when I type in another record number to call another set of data. what is happening is not all the controls get refreshed with the correct data. meaning some data is left behind from the previous record.
e.g. I type in 41 into the search textbox and press the search button. the SP fires off and the reader populates the controls below. everything is fine. But if I type in say, 42 into the textbox and press the search button, the SP gets fired off and so does the reader. The issue is that some of the controls still have the data from record 41 and not record 42.
it seems like the reader is stopping during the SP execution ???
any help would be appreciated.
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
Dim param As SqlParameter
Dim con As New SqlConnection(MyConnection)
Try
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "MYSP"
param = New SqlParameter("@MY_FIELD", l8.Text)
param.Direction = ParameterDirection.Input
param.DbType = DbType.Int32
cmd.Parameters.Add(param)
reader = cmd.ExecuteReader()
If reader.HasRows Then
While reader.Read
t16.Text = reader("field1") & ""
ddl17.Text = reader("field2") & ""
t17.Text = reader("field3") & ""
ddl18.Text = reader("field4") & ""
End While
End If
reader.Close()
I'm using a datareader to populate some controls. Textboxes and comboboxes. I'm typing a record number into a textbox to execute the reader below. everything gets populated correctly except when I type in another record number to call another set of data. what is happening is not all the controls get refreshed with the correct data. meaning some data is left behind from the previous record.
e.g. I type in 41 into the search textbox and press the search button. the SP fires off and the reader populates the controls below. everything is fine. But if I type in say, 42 into the textbox and press the search button, the SP gets fired off and so does the reader. The issue is that some of the controls still have the data from record 41 and not record 42.
it seems like the reader is stopping during the SP execution ???
any help would be appreciated.
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
Dim param As SqlParameter
Dim con As New SqlConnection(MyConnection)
Try
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "MYSP"
param = New SqlParameter("@MY_FIELD", l8.Text)
param.Direction = ParameterDirection.Input
param.DbType = DbType.Int32
cmd.Parameters.Add(param)
reader = cmd.ExecuteReader()
If reader.HasRows Then
While reader.Read
t16.Text = reader("field1") & ""
ddl17.Text = reader("field2") & ""
t17.Text = reader("field3") & ""
ddl18.Text = reader("field4") & ""
End While
End If
reader.Close()