Solved

Populate ASP Label from SQL Database

Posted on 2014-04-06
6
389 Views
Last Modified: 2014-04-07
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

Open in new window

0
Comment
Question by:Southern_Gentleman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39982419
Did you mean to say you want to send Orderid in query and then retrive Order date ?

try this

  Dim orderdate As Date
 If Not String.IsNullOrEmpty(Request.QueryString("OrderID")) AndAlso Date.TryParse(Request.QueryString("OrderID"), orderdate) Then

 Dim command As SqlCommand = New SqlCommand("select OrderDate from [Orders] where OrderID = " & Request.QueryString("OrderID"),connection)
        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
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39982439
Your code looks a little confused. In this line:
If Not String.IsNullOrEmpty(Request.QueryString("OrderID")) AndAlso Date.TryParse(Request.QueryString("OrderID"), orderdate) Then

Open in new window

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?
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39982444
try this

Dim orderdate As Date
 If Not String.IsNullOrEmpty(Request.QueryString("OrderID")) Then

 Dim command As SqlCommand = New SqlCommand("select OrderDate from [Orders] where OrderID = " & Request.QueryString("OrderID"),connection)
        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
0
 

Author Comment

by:Southern_Gentleman
ID: 39984059
Ok, so I got the sqlconnection but how do I assign my label (lblOrderDate) to the connection string.
0
 

Author Closing Comment

by:Southern_Gentleman
ID: 39984561
I was finally able to figure it out. Thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question