Solved

Recordset variables

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

15 Experts available now in Live!

Get 1:1 Help Now