Solved

Populate ASP Label from SQL Database

Posted on 2014-04-06
6
388 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

Technology Partners: 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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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