Southern_Gentleman
asked on
Populate ASP Label from SQL Database
I'm a super nubie to Visual Studio and I've been working on this but I can't seem to retrieve the correct data to show in my ASP Label. I want to use the querystring ("OrderID") in my sql string to retrieve the orderdate field of my table. It keeps populating 12:00AM
If Not IsPostBack Then
Dim orderdate As Date
If Not String.IsNullOrEmpty(Request.QueryString("OrderID")) AndAlso Date.TryParse(Request.QueryString("OrderID"), orderdate) Then
Dim sql As String = "select * from [Orders] where OrderID = " & orderdate.ToString()
End If
lblOrderDate.Text = orderdate
End If
Your code looks a little confused. In this line:
Which field are you trying to use to query the database, and what field do you want to display in your label?
If Not String.IsNullOrEmpty(Request.QueryString("OrderID")) AndAlso Date.TryParse(Request.QueryString("OrderID"), orderdate) Then
You are checking two Querystring values, one of which the name suggests is a date.Which field are you trying to use to query the database, and what field do you want to display in your label?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, so I got the sqlconnection but how do I assign my label (lblOrderDate) to the connection string.
ASKER
I was finally able to figure it out. Thanks again
try this
Dim orderdate As Date
If Not String.IsNullOrEmpty(Reque
Dim command As SqlCommand = New SqlCommand("select OrderDate from [Orders] where OrderID = " & Request.QueryString("Order
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
Do While reader.Read()
orderdate =reader.GetDateTime(0)
Loop
End If
reader.Close()
End If