Home All Groups Group Topic Archive Search About
Author
17 Jun 2009 2:04 PM
Ron H.
I am trying to read in records from a database into a custom table into the
aspx page. GridView, DetailsView, and FormView do not fit in with what I am
trying to do. Therefore I am attempting to hand code this procedure into the
page. I tried using SQLDataReader, but it is not working.  Can anyone show
me how to accomplish this task.
Generating multiple errors

-----------------------

<% Dim myReader As SQLDataReader

sqldatareader = myCommand.ExecuteReader()%>

----------------

Here is the old ASP Code I am trying to convert to ASP.Net

--------Old ASP I'm Trying To Convert--------
<%
Dim sqltext
sqltext = "SELECT * FROM Services"

Dim RS
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.CursorType = adOpenStatic
RS.Open sqltext, "DSN=services"
RS.MoveFirst
%>

<% While NOT oRSp.EOF %>
    <tr>
        <td> <% Response.Write oRSp("ServiceName") %> </td>
        <td> <% Response.Write oRSp("Price")  %> </td>
    </tr>
    <% oRSp.MoveNext
Wend %>
----------------------------

Author
17 Jun 2009 2:30 PM
Alexey Smirnov
Show quote Hide quote
On Jun 17, 4:04 pm, "Ron H." <fd***@jfsk.net> wrote:
> I am trying to read in records from a database into a custom table into the
> aspx page. GridView, DetailsView, and FormView do not fit in with what I am
> trying to do. Therefore I am attempting to hand code this procedure into the
> page. I tried using SQLDataReader, but it is not working.  Can anyone show
> me how to accomplish this task.
> Generating multiple errors
>
> -----------------------
>
> <% Dim myReader As SQLDataReader
>
> sqldatareader = myCommand.ExecuteReader()%>
>
> ----------------
>
> Here is the old ASP Code I am trying to convert to ASP.Net
>
> --------Old ASP I'm Trying To Convert--------
> <%
> Dim sqltext
> sqltext = "SELECT * FROM Services"
>
> Dim RS
> Set RS = Server.CreateObject("ADODB.RecordSet")
> RS.CursorType = adOpenStatic
> RS.Open sqltext, "DSN=services"
> RS.MoveFirst
> %>
>
> <% While NOT oRSp.EOF %>
>     <tr>
>         <td> <% Response.Write oRSp("ServiceName") %> </td>
>         <td> <% Response.Write oRSp("Price")  %> </td>
>     </tr>
>     <% oRSp.MoveNext
> Wend %>
> ----------------------------

Dim myConnection As New SqlConnection(myConnectionString)
    Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As SqlDataReader = myCommand.ExecuteReader
(CommandBehavior.CloseConnection)
    While myReader.Read()
        Console.WriteLine(myReader.GetString(0))
    End While
    myReader.Close()

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executereader(VS.71).aspx
Are all your drivers up to date? click for free checkup

Author
17 Jun 2009 2:35 PM
sloan
1.  FORGET you ever knew anything about
<td> <% Response.Write oRSp("ServiceName") %> </td>
REMOVE this thinking from your arsenal.

2.  The asp:repeater gives you alot of control over the display, it also
needs the most coding to get it.  But I think its what you want.



Here is a quick explanation:

http://weblogs.asp.net/brichardson/archive/2003/04/02/4632.aspx


Here is a slightly different one using a DataSet:
http://support.microsoft.com/kb/306154
But shows you a little more of the asp:repeater "tweaking".






Show quoteHide quote
"Ron H." <fd***@jfsk.net> wrote in message
news:EE6_l.11934$he4.5486@bignews3.bellsouth.net...
>
> I am trying to read in records from a database into a custom table into
> the
> aspx page. GridView, DetailsView, and FormView do not fit in with what I
> am
> trying to do. Therefore I am attempting to hand code this procedure into
> the
> page. I tried using SQLDataReader, but it is not working.  Can anyone show
> me how to accomplish this task.
> Generating multiple errors
>
> -----------------------
>
> <% Dim myReader As SQLDataReader
>
> sqldatareader = myCommand.ExecuteReader()%>
>
> ----------------
>
> Here is the old ASP Code I am trying to convert to ASP.Net
>
> --------Old ASP I'm Trying To Convert--------
> <%
> Dim sqltext
> sqltext = "SELECT * FROM Services"
>
> Dim RS
> Set RS = Server.CreateObject("ADODB.RecordSet")
> RS.CursorType = adOpenStatic
> RS.Open sqltext, "DSN=services"
> RS.MoveFirst
> %>
>
> <% While NOT oRSp.EOF %>
>    <tr>
>        <td> <% Response.Write oRSp("ServiceName") %> </td>
>        <td> <% Response.Write oRSp("Price")  %> </td>
>    </tr>
>    <% oRSp.MoveNext
> Wend %>
> ----------------------------
>
>
>
Author
17 Jun 2009 2:42 PM
Mark Rae [MVP]
"sloan" <sl***@ipass.net> wrote in message
news:ukqWSj17JHA.4100@TK2MSFTNGP06.phx.gbl...

> 1.  FORGET you ever knew anything about
> <td> <% Response.Write oRSp("ServiceName") %> </td>
> REMOVE this thinking from your arsenal.

What you say is 100% correct, but the problem here is that the OP currently
has nothing to replace this with because he, as we have seen countless
times, is trying to somehow "convert" ASP Classic to ASP.NET...

Without the absolute basics of ASP.NET, it will be an almost impossible task
to get anything done...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Author
17 Jun 2009 2:39 PM
Mark Rae [MVP]
"Ron H." <fd***@jfsk.net> wrote in message
news:EE6_l.11934$he4.5486@bignews3.bellsouth.net...

Ron,

> Can anyone show me how to accomplish this task.

The biggest mistake people make when coming to ASP.NET from ASP Classic is
to imagine that ASP.NET is somehow the "next version" of ASP Classic. It
isn't - not even close. The best advice I can give you is to forget
everything you ever knew about ASP Classic - (almost) none of it will be of
any use to you at all in ASP.NET...

I would then advise you to get a copy of this:
http://www.amazon.co.uk/Beginning-ASP-NET-3-5-2008-Professional/dp/1590598911/ref=sr_1_1?ie=UTF8&s=books&qid=1245249145&sr=8-1
and work your way through it.

> Dim RS
> Set RS = Server.CreateObject("ADODB.RecordSet")
> RS.CursorType = adOpenStatic
> RS.Open sqltext, "DSN=services"
> RS.MoveFirst
> %>

Firstly, ASP.NET uses ADO.NET, not ADO, so none of the above will be of any
use to you in ASP.NET... ADO.NET uses DataSets, DataTables and DataReaders,
not RecordSets.


>    <tr>
>        <td> <% Response.Write oRSp("ServiceName") %> </td>
>        <td> <% Response.Write oRSp("Price")  %> </td>
>    </tr>
>    <% oRSp.MoveNext

Secondly, apart from some very specific and quite rare occasions, ASP.NET
does not use Response.Write to "write out" HTML. ASP.NET is object-oriented,
unlike ASP Classic which is essentially linear. So, to do things like create
and populate HTML tables, you use things like the <asp:GridView /> web
control. This involves creating the HTML markup for the web control on the
aspx page and then wiring it up in your code behind page.


I realise that this isn't what you wanted to hear but, without acquiring the
absolute basics of ASP.NET (which the above book will give you and more),
then you really will find it almost impossible to get anywhere...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Bookmark and Share