Movenext and ASP.net


R

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 %>
----------------------------
 
Ad

Advertisements

G

Guest

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
 
S

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".
 
R

Ron H.

I keep getting the folowing error:

A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured
to allow remote connections. (provider: SQL Network Interfaces, error: 26 -
Error Locating Server/Instance Specified)

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

<% @Import Namespace="System.Data.SqlClient" %>

<% Dim mySelectQuery As String = "SELECT ServiceName, Price FROM Services"

Dim myConnectionString As String = "Data
Source=C:\Website\App_Data\database.mdb;"

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()%>

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

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
 
R

Ron H.

Nevermind I see where I made my error. I used the wrong datareader
(sqldatareader). Thanks for you help.


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
 
Ad

Advertisements

G

Guest

Nevermind I see where I made my error. I used the wrong datareader
(sqldatareader). Thanks for you help.








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.sqlcomm...

Hi Ron,

yes, please use OleDb for this. You will find many examples in the
internet

http://www.w3schools.com/aspnet/aspnet_dbconnection.asp
http://www.google.com/search?q=mdb+asp.net

Hope this helps
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top