Solved

how to diaplay a record from a dataset in a paragraph

Posted on 2008-10-22
6
198 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
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.

 

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

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

Title # Comments Views Activity
Jquery autocomplete 10 68
asp.net mvc input file 2 32
ADO.NET ENTITY DATA MODEL 3 30
Where can I ask about my ASP.NET MVC project? 6 21
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

24 Experts available now in Live!

Get 1:1 Help Now