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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I return single value from DB to label.text

Status
Not open for further replies.

paulhudson

Programmer
Jan 20, 2005
8
GB
I am querying a database - the query can only have one row/cell returned. The query works fine when run against the database. What I am doing is using the result to form part of a url for a redirection. Trouble is I cannot see how you can retrieve a value without creating a bindable object.

Can anyone help me with this?

The code I have used below throws the following error "Index was outside the bounds of the array. " when I try to bind the results to a label called lblmessage

Code:
sSQL = "Select ...."
Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("testconnString"))
Dim oCommand As New OleDbCommand(sSQL, oConnect)
Try
	oConnect.Open()
        lblmessage.text = oCommand.ExecuteScalar(CommandBehavior.CloseConnection)
	Catch oErr As Exception
	If oConnect.State <> ConnectionState.Closed Then
		oConnect.Close()
	End If
        lblErr.Text = oErr.Message
End Try
 
Try using the example from faq855-5662 and set the label's text value whilst in the loop.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Many thanks for such a prompt response. It works a treat. Amazingly enough in all this sunshine, my day has become brighter still. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top