Exforsys
+ Reply to Thread
Results 1 to 4 of 4

help in connecting to database

This is a discussion on help in connecting to database within the ASP forums, part of the Programming Talk category; hi I am trying to add records through asp to sql database. But I couldnt somehow. I am pasting the ...

  1. #1
    shrig is offline Junior Member Array
    Join Date
    Jul 2004
    Answers
    2

    help in connecting to database

    hi
    I am trying to add records through asp to sql database. But I couldnt somehow. I am pasting the code which I tried to write. Can anybody tell the reason why its not reaching to database. Appreciate your help.

    <%
    FUNCTION fixQuotes(theString)
    fixQuotes = Replace (theString, \"\'\",\"\'\'\&quot
    END FUNCTION
    username = TRIM( Request( \"username\" ))
    password = TRIM( Request( \"password\" ))
    IF username <> \"\" AND password <> \"\" THEN
    mySQL = \"INSERT Webusers (username,password ) VALUES \"
    mySQL = MySQL & \"(\'\"&fixQuotes(username) & \"\',\'\"& fixQuotes(password) & \"\')\"
    Set Con=Server.CrateObject( \"ADODB.Connection\" )
    Con.Open \"DSN=test;DATA SOURCE=sqlsrvrname;UID=sa;PWD=sa;DATABASE=name\"
    END IF
    %>
    <html>
    <head><title>Insert Data</title>
    <body>
    <form mehtod=\"post\" action=\"insertData.asp\">
    <p>Username: <input name=\"username\" size=20>
    <p>Password: <input name=\"password\" type=\"password\" size=20>
    <p><input type=\"submit\" value=\"add Data\">
    </form>
    </body>
    </html>


  2. #2
    sanereddy Guest

    Re:help in connecting to database

    seems to be there are few errors in the code,

    here is the basic shell it should be

    create test datasource name from ODBC administrator first. Here is the ASP code to connect to SQl Server using ADODB. You can include your cleanup code anywhere.

    <%
    yourname = request.form(\"yourname\&quot
    yourpass = request.form(\"yourpass\&quot

    Set cn = Server.CreateObject(\"ADODB.Connection\&quot
    Set rs = Server.CreateObject(\"ADODB.Recordset\&quot

    sql = \"insert into Webusers (username,password)\"

    sql = sql & \" values( \'\" & yourname & \"\' , \'\" & yourpass & \"\' )\"

    cn.Open \"test\"
    rs.Open sql, cn
    %>

    Hope this helps. if not let me know ,I will provide working full ASp scripts for you to be able to run any DML statements.

    Thanks,
    sanereddy


  3. #3
    shrig is offline Junior Member Array
    Join Date
    Jul 2004
    Answers
    2

    Re:help in connecting to database

    reddy garu I have tried in your way too. but somehow its not working what could be the reason pls gimme solution. thx.


  4. #4
    mtajim is offline Junior Member Array
    Join Date
    Apr 2006
    Answers
    22
    Use this code for creating a DSN less connection to ur database

    <%
    dim con
    dim adocon
    Set adoCon = Server.CreateObject("ADODB.Connection")

    Con = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Enter your Database name here")
    %>


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...