Solved

how to diaplay a record from a dataset in a paragraph

Posted on 2008-10-22
6
197 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
  • 4
  • 2
6 Comments
 
LVL 37

Expert Comment

by:samtran0331
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

by:samtran0331
Comment Utility
>>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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

18 Experts available now in Live!

Get 1:1 Help Now