Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From Asp to Asp.Net..? 1

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

I have used the below code in classic Asp:
==============================================
Set Conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=sqloledb;" & _
"Data Source=MyServer;" & _
"Initial Catalog=MyDatabase;" & _
"User Id=MyUser;" & _
"Password=MyPwd;"
set rs=Server.CreateObject("ADODB.Recordset")
Sql=Select Field1,Field2 from Table1
rs.open sql,conn,3,3
rs.Close
Conn.Close
Set Conn = Nothing
================================================
What changes do I have to do in .Net in order to make it work in the Page_Load event?

/Kent J.
 
I think the key line is
rs.open sql,conn,3,3

which as far as I remember creates a disconnected recordset, correct?

In this case, you'll use the DataAdapter and DataTable objects of ADO.net rather than the rs.

In the case of a connected rs, you'll use the DataReader

You really need to learn the basics of ASP.net and ADO.net I'm not trying to be clever when I say that if you don't want to do this, and the page works in asp, then leave it in asp



Mark [openup]
 
I realize that it's not the new and cool way of doing things (which is indeed newer and cooler), but can't he just add a reference to the old ADO object library, then instantiate everything in the code-behind?
 
Yes. Sorry I did not think of it that way. I thought it was required to rewrite it completely in asp.net.

If you want to leave it, but just get it running under asp.net, then you don't even have to add the reference.

In fact, if you just paste it in to visual studio, it will almost tell you what you need to do - it will remove the set statements, and draw squiggly lines under undeclared variables. You can fix the latter by adding an option explicit off to the top of the module. Finally, you'll need the sql variable to be enclosed in quotes.

Oh - one more thing - you'll need to set the aspcompat property of the page to true.

Doing what boulder says will give you type safety - you can then get rid of the CreateObject late binding.

Sorry to have jumped the gun

:)

Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top