Solved

Populate ASP Label from SQL Database

Posted on 2014-04-06
6
382 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
  • 2
  • 2
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I was finally able to figure it out. Thanks again
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now