Solved

Recordset variables

Posted on 2006-07-19
5
647 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 50
Change to file doesn't show up 16 93
orderby list (from Json) 1 42
Shared Service Environment 2 54
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…
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 use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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