Solved

how to diaplay a record from a dataset in a paragraph

Posted on 2008-10-22
6
200 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
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 500 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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