Solved

Populate ASP Label from SQL Database

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

14 Experts available now in Live!

Get 1:1 Help Now