|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Movenext and ASP.netaspx 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 %> ----------------------------
Show quote
Hide quote
On Jun 17, 4:04 pm, "Ron H." <fd***@jfsk.net> wrote: Dim myConnection As New SqlConnection(myConnectionString)> 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 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 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 %> > ---------------------------- > > > "sloan" <sl***@ipass.net> wrote in message What you say is 100% correct, but the problem here is that the OP currently 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. 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... "Ron H." <fd***@jfsk.net> wrote in message Ron,news:EE6_l.11934$he4.5486@bignews3.bellsouth.net... > 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 Firstly, ASP.NET uses ADO.NET, not ADO, so none of the above will be of any > Set RS = Server.CreateObject("ADODB.RecordSet") > RS.CursorType = adOpenStatic > RS.Open sqltext, "DSN=services" > RS.MoveFirst > %> use to you in ASP.NET... ADO.NET uses DataSets, DataTables and DataReaders, not RecordSets. > <tr> Secondly, apart from some very specific and quite rare occasions, ASP.NET > <td> <% Response.Write oRSp("ServiceName") %> </td> > <td> <% Response.Write oRSp("Price") %> </td> > </tr> > <% oRSp.MoveNext 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...
Other interesting topics
Is there a way to keep the StreamWriter open?
Visual Basic is Dead! Detailsview updading issue Basic question: returning @@IDENTITY from stored procedure... enum or static class Document markup language version question Skinning Question for checkboxes Custom Authentication Employee TimeSheet/Projects Formview hijinks |
|||||||||||||||||||||||