Results 1 to 3 of 3

Thread: database access

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    India
    Posts
    14

    Question database access

    Hello friends,
    i wanna to know that how to access the database in a website through asp. The server where my site is hosted is asp supported. I dont know the way as how to create DSN etc. in server.
    in short, i want to create a form in my site so that users can submit their queries. i want to use ACCESS for database.

    please guide me.

    Thanks

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    To create a DSN o go to control panel - odbc ....but if its a shared server then u can ask the server guys to create a DSN for you.

    To acccess an DB, its not compulsory to use a DSN, you can use Jet Provider (I dont know what to call these types of connections to DB)..

    Heres, some code
    Code:
    'Assume you want to add username and password  to the DB.
    
    'Get the values in vars.
    Muser = request.form("TxtUserName")
    MPass= request.form("txtPassword")
    'String to connect to the DB
    MyConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mapath("/") & "\MyDB.mdb"
    
    'Assumes u upload your access DB with the Table "Mytable" and place it inthe root folder.
    
    'Open Database connection:
    
    set conn = server.createObject("ADODB.Connection")
    set rs = server.CreateObject("ADODB.RecordSet")
    
    conn.open MyConnectionString
    'certain settings
    rs.cursorType = adopenKeySet
    rs.locktype = adlockoptimistic
    rs.cursorlocation = adUseServer
    rs.activeConnection = conn
    rs.open "MyTableName"
    rs.addNew
    rs("UserNameField") = Muser
    rs("MpassWordField") = Mpass
    
    'Update the Table
    rs.Update
    
    'close recordset
    rs.close
    set rs = nothing
    conn.close
    set conn = nothing
    Hope this helps..

  3. #3
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459
    I assume you are adding FullName and Age to a table named PersonalData and file named somedb.mdb

    Code:
    <%
    MName = Request("FullName")
    MAge = Request("Age")
    
    Dim Conn, Rst, SQL
    Set Conn = Server.CreateObject("ADODB.connection")
    Conn.Open "DBQ=" & Server.Mappath("somedb.mdb") & ";Driver={Microsoft Access
    
    SQL = "INSERT INTO PersonalData (FullName, Age) VALUES ('" & MName & "', '" & MAge & "'"
    
    Set R = Server.CreateObject("ADODB.Recordset")
    
    On Error Resume Next
    R.Open SQL, Conn
    
    If Err <> 0 Then
         Response.Write Err.Description
    Else
         Response.Write "Recorded added to db" & Chr(10)
    End If
    %>
    Hope this helps!
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

Posting Permissions

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



Click Here to Expand Forum to Full Width