?
Solved

Recordset variables

Posted on 2006-07-19
5
Medium Priority
?
651 Views
Last Modified: 2012-05-05
Experts,

Is it possible to display a recordset variable in ASP.Net as was in the old ASP.

 Ok, in ASP this would display a variable that was generated by a query of a database: <% =RS("controlNum") %>
"RS" being the variable that contained the recordset and "controlNum" a column in the db

How can I display a record set variable in the same manner as the old ASP using the query below?

<asp:SqlDataSource ID="myDB" runat="server" ConnectionString="<%$ ConnectionStrings:myDB %>" SelectCommand="SELECT * FROM [books] WHERE ([bookID] = @bookID)">
       <SelectParameters>
               <asp:QueryStringParameter DefaultValue="1" Name="bookID" QueryStringField="bookID" Type="Int32" />
        </SelectParameters>
 </asp:SqlDataSource>

Thanks for your help!

0
Comment
Question by:rruth
[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
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17142212
Are you looking to stay away from controls like GridView, DataList, Repeater?

Bob
0
 

Author Comment

by:rruth
ID: 17142646
Bob,

The studies I've been going through teach how to use the controls but I would like to know how to do it manually also. I'm a Coldfusion programmer with experience using ASP. I think it would help me if could also program .NET manually as I do CF or ASP. I would really appeciate any help with displaying a recordset variable.

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17160795
This is an example of VB.NET code to iterate an SqlDataSource:

   Dim args As New DataSourceSelectArguments()
   Dim view As DataView = Me.SqlDataSource1.Select(args)
   For Each row As DataRowView In view
      Dim street As String = row("Street").ToString()
      Dim city As String = row("City").ToString()
   Next

What you do with this example is up to you.  If you want more information, just let me know.

Bob
0
 

Author Comment

by:rruth
ID: 17163353
Bob,

Ok, I see what you're doing but what happens if my query returns all columns of one record as with a "where" clause. Say two of the columns being returned in the record are called "firstName" and "lastName". I use to be able to display these columns of the query by this code:

 My name is: <% =RS("firstName") %> <% =RS("lastName") %>.

The output for this would be: "My name is: Bill Gates."

Again, "RS" being the variable that contained the recordset and "firstName" and "lastName"  columns in the db. By doing this there are no Gridviews, DetailsView, or control structures being used. Can I do this in ASPX and how? I've upped the points to 250 if that means anything.

Thank you for your help!

Rob
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 17163581
Rob,

1) It is not possible to accomplish the same thing with .aspx pages that you could with .asp pages, but why would you need it?

2) The example that I showed you could easily be extended to create an HTML table that could be rendered on the page.

3) It sounds like you are looking for an inline expression.  You can do it like this:

  <% =BuildName() %>

   where BuildName is a public function that returns a string:

   Public Function BuildName() As String
     Dim args As New DataSourceSelectArguments()
     Dim view As DataView = Me.SqlDataSource1.Select(args)
     Dim row As DataRowView = view(0)
     Dim first As String = row("firstName").ToString()
     Dim last As String = row("lastName").ToString()
     Return "My name is " & first & " " & last
   End Function

Bob
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…

801 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