Hocke_sweden
asked on
convert asp to .net
I have a application with a lot of pagesI want to convert from asp to .net
I have tried to convert it to with the program asp2aspx from Netcoole, but the code don't work, the big problem is the database connection. Can someone help me to convert these code to asp.net?
Im a beginner in .net
I have tried to convert it to with the program asp2aspx from Netcoole, but the code don't work, the big problem is the database connection. Can someone help me to convert these code to asp.net?
Im a beginner in .net
<%
connectstring = "server=testserver;Provider=SQLOLEDB;uid=sa;pwd=1234;Trusted_Connection=True;database=testdatabase"
Dim rs
Dim Conn
Class Datebase_Connections
function connOpen()
set Conn = Server.CreateObject("ADODB.Connection")
Conn.open connectstring
end function
function connClose()
Conn.Close
set Conn = nothing
end function
end class
Set Connections = New Datebase_Connections
Call Connections.ConnOpen
sql="select top 10 * from users"
set rs=conn.execute(sql)
do until rs.eof
response.write ("<br>Long:"&rs("login"))
rs.movenext
loop
Call Connections.ConnClose
%>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks it works good, it was for vb.net, I post the code again, it was some small error in the code.
Is it possible to make a function to open the database with the connection string, so i don't need to write it everywhere?
Is it possible to make a function to open the database with the connection string, so i don't need to write it everywhere?
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%
Dim SQL As String = String.Empty
Dim rs As SqlClient.SqlDataReader
Dim Conn As New SqlClient.SqlConnection("user id=sa;data source=testserver;persist security info=True;initial catalog=testdatabase;password=1234")
SQL = "select top 10 * from users"
Dim Cmd As New SqlClient.SqlCommand(SQL)
If Conn.State <> ConnectionState.Open Then
Conn.Open()
End If
Cmd.CommandType = CommandType.Text
Cmd.Connection = Conn
rs = Cmd.ExecuteReader()
While rs.Read()
Response.Write("<br>Login:" & rs("login").ToString)
End While
rs.Close()
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
%>
Why don't you put your function in a data access layer (DAL) class project to make it common to the rest of the pages?
Check this out:
http://msdn.microsoft.com/en-us/library/aa581778.aspx
http://www.15seconds.com/issue/030317.htm
Check this out:
http://msdn.microsoft.com/en-us/library/aa581778.aspx
http://www.15seconds.com/issue/030317.htm
ASKER
The asp project is big and complicated, and the work to convert and got it work with vb.net is big enough for the moment. I want to do it so easy I can for me so I can get the project in goal.
When it works in vb.net I will probably take the advantages of vb.net, now Im glad if I can do it "fast and dirty"
I read about it in the url you posted and like the idea of DAL, its smart!
But I want to start with functions first :)
When it works in vb.net I will probably take the advantages of vb.net, now Im glad if I can do it "fast and dirty"
I read about it in the url you posted and like the idea of DAL, its smart!
But I want to start with functions first :)
OK. How about creating a shared function in a class file? You could move your function in a class file and let your pages call directly this shared function. Check this out:
Check lesson 3 of the link below:
http://www.codeproject.com/KB/vb/OOPS_In_VBNET.aspx
Check this as well:
http://tutorials.beginners.co.uk/vb-net-programming-part-4-shared-or-class-members.htm
Check lesson 3 of the link below:
http://www.codeproject.com/KB/vb/OOPS_In_VBNET.aspx
Check this as well:
http://tutorials.beginners.co.uk/vb-net-programming-part-4-shared-or-class-members.htm
Read data from SqlConnection (VB.net)
http://www.java2s.com/Code/ASP/ADO.net-Database/ReaddatafromSqlConnectionVBnet.htm