Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Recordset variables

Posted on 2006-07-19
5
Medium Priority
?
652 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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