Textbox binding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am tryin to bind numerous textboxes to the results of my stored procedure.

I cannot get it to work. Is this the righ way to go about it?
....

Try
Cn.Open()
Dim reader5 As SqlDataReader
reader5 = cmdDetails.ExecuteReader()
While reader5.Read
txtName.Text = (reader5.GetString("Name"))
txtLength.Text = (reader5.GetString("Length").ToString)
txtBeds.Text = (reader5.GetInt16("Beds").ToString)
txtTotOnSite.Text = (reader5.GetInt16("No_Onsite").ToString)
txtPrice.Text = (reader5.GetSqlMoney("Cost").ToString)
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try

I cannot seem to see the results in my textboxes. I wasnt sure if this was the way to do this as this is normally how i fill a comobox. I just modified the code to suit.

Any help?
 
Well no matter what you are doing, your textboxes are only going to be
filled with the last row of your reader. Instead of using the while loop,
you can just make a call to reader5.Read to fetch the first row.

To answer your question, I'd make sure your query is actually returning
data, I can't see how you constructed your command object, so I can't help
you there.

Also, since you are just putting the results into a text field, why not
simplfy your code and just to this

txtName.Text = reader5("Name")

HTH,
--Michael

Bhavna said:
Hello,

I am tryin to bind numerous textboxes to the results of my stored procedure.

I cannot get it to work. Is this the righ way to go about it?
..

Try
Cn.Open()
Dim reader5 As SqlDataReader
reader5 = cmdDetails.ExecuteReader()
While reader5.Read
txtName.Text = (reader5.GetString("Name"))
txtLength.Text = (reader5.GetString("Length").ToString)
txtBeds.Text = (reader5.GetInt16("Beds").ToString)
txtTotOnSite.Text = (reader5.GetInt16("No_Onsite").ToString)
txtPrice.Text = (reader5.GetSqlMoney("Cost").ToString)
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try

I cannot seem to see the results in my textboxes. I wasnt sure if this was
the way to do this as this is normally how i fill a comobox. I just modified
the code to suit.
 
Back
Top