Solved

Recordset variables

Posted on 2006-07-19
5
646 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
  • 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 250 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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