
- Forum
- Programming Talk
- ASP
- help in connecting to database
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 ...
-
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, \"\'\",\"\'\'\"
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>
-
07-01-2004, 09:33 AM #2sanereddy 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\"
yourpass = request.form(\"yourpass\"
Set cn = Server.CreateObject(\"ADODB.Connection\"
Set rs = Server.CreateObject(\"ADODB.Recordset\"
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
-
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.
-
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

Reply With Quote





