Solved

how to diaplay a record from a dataset in a paragraph

Posted on 2008-10-22
6
199 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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