Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Database Programming from ASP Classic to ASP.NET

    Hi,

    I've migrated from ASP Classic to ASP.NET but I'm having real trouble learning the new ADO.NET way of database programming. I used to use the following two functions for creating ASP Classic database connections:

    Code:
    <%
    Function CreateConn()
    
     dim Connect
     dim cnDB
     Connect = "Provider=SQLOLEDB.1;Data Source=DBASESVR;Initial Catalog=Contractors;uid=user;pwd=pass"
     Set cnDB = Server.CreateObject("ADODB.Connection")
     cnDB.Open(Connect)
     Set CreateConn = cnDB
    
    End Function
    
    Function SQLQuery(cnDB, queryString)
    
     dim rsADO
     Set rsADO = Server.CreateObject("ADODB.Recordset")
     rsADO.ActiveConnection = cnDB
     rsADO.Open(queryString)
     Set SQLQuery = rsADO
    
    End Function
    %>
    And then display data to my ASP Classic pages with code like this:

    Code:
    <%
    dim cnDB
    Set cnDB = CreateConnection
    
    SqlCommandView = "SELECT ID, Name FROM Contacts WHERE ID=1"
    Set RsView = SQLQuery(cnDB, SqlCommandView)
    
    Dim DataVariable
    DataVariable = RsView("Name")
    %>
    How do I convert this process to ADO.NET? Help would be muchly appreicated, thanks!

    Alex

  • #2
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I ended up finding the following code that is working well:

    Code:
    Dim MyConnection As System.Data.SqlClient.SqlConnection
    Dim MyCommand As System.Data.SqlClient.SqlCommand
    Dim MyReader As System.Data.SqlClient.SqlDataReader
    
    nameSQL = "SELECT Name FROM [BMIS Live Database].dbo.[BMIS Live Database$Vendor] WHERE No_ = '" & Dt(1) & "'"
    MyConnection = New System.Data.SqlClient.SqlConnection("server=DBASESVR;uid=CSC;pwd=CSC!;database=BMIS Live Database")
    MyConnection.Open()
    MyCommand = New System.Data.SqlClient.SqlCommand(nameSQL, MyConnection)
    MyReader = MyCommand.ExecuteReader
    
    Response.Write(MyReader.GetValue(0))
    Does anyone know if there is a way to reuse this connection code into a function so I can call it like I did in ASP with the CreateConnection and SQLQuery functions? Thanks.

    Alex


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •