Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to diaplay a record from a dataset in a paragraph

Posted on 2008-10-22
6
Medium Priority
?
204 Views
Last Modified: 2012-06-27
I have a simple querry bellow. How do I display the NewPONumber from the dataset within a paragraph in the body of the asp.net page?

Dim strSQLPO As String
        strSQLPO = "SELECT max(po_num)+1 as NewPONumber from imtbl_purchase_order where po_num is not null"
        Dim DBCommandPO As New SqlDataAdapter(strSQLPO, "MyCOnnection")
        Dim POds As New DataSet
        DBCommandPO.Fill(POds)
0
Comment
Question by:soccerman777
[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
  • 4
  • 2
6 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 22782101
Put a label on your form.

Since you're only returning one value... at the end of your code you posted:
Label1.Text = POds.Tables(0).Rows(0)("NewPONumber").ToString()

That's the quick answer....I'm away from my desk...but tomorrow, I can give you a more efficient sample...
Basically, if you know you are returning only one single value, there is someting called "ExecuteScalar" which is much much less overhead than declaring a full dataset to get just the one value.... ExecuteScalar can be used with the basic "Using" structure I posted in your other question...
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 2000 total points
ID: 22782116
actually, just cutting and pasting from the other post, the below should work, notice that I removed the transaction because you aren't actually doing anything besides selecting data so you don't have to worry about committing/rolling back a transactino
Dim strSQLPO As String
        strSQLPO = "SELECT max(po_num)+1 as NewPONumber from imtbl_purchase_order where po_num is not null"         
 
  Using MyConn As New SqlConnection("myconnectionstring")
                MyConn.Open()
                 Dim MyCmd As New SqlCommand(strSQLPO, MyConn)
                Try
                    Label1.Text = MyCmd.ExecuteScalar()
                Catch ex As Exception
               Finally
                    If MyConn.State = ConnectionState.Open Then MyConn.Close()
                End Try
            End Using

Open in new window

0
 

Author Closing Comment

by:soccerman777
ID: 31509182
acctually I was hopeing there was some way to display the data without using a control. I know how to attach it to a control. I just would like to output a var in a paragraph or somewhere on a page without having to make a control.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:soccerman777
ID: 22785656
I will just put it into a label for now.
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 22786918
>>I just would like to output a var in a paragraph or somewhere on a page without having to make a control.

You still need some kind of container...so instead of a control, you coul also use a public variable....

So in your code page, outside of any sub routine:
Public MyParagraph As String = ""

And then in the db code, instead of:
Label1.Text = MyCmd.ExecuteScalar()

You can:
MyParagraph = MyCmd.ExecuteScalar()

And then in your aspx:
<%= MyParagraph %>
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 22786969
Even though the public variable technique above works to display data without using a control...I would still recommend you use a control....mainly either a label or a literal.
A label actually renders its text inside of <span> tags...the plus side of that being you can apply css or styles to it quickly.
A literal will render its text "as is"...same as using the public variable technique above.
It's just that a good rule of thumb with ASP.Net is to not use code blocks (the "<%= %>") except when absolutely necessary.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

705 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