Exforsys

Free Training

33

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 ...

Go Back   Exforsys > Programming Talk > ASP

Exforsys.com

  #1 (permalink)  
Old 07-01-2004, 03:58 AM
Junior Member
 
Join Date: Jul 2004
Posts: 2
shrig
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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-01-2004, 08:33 AM
sanereddy
Guest
 
Posts: n/a
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-02-2004, 11:11 PM
Junior Member
 
Join Date: Jul 2004
Posts: 2
shrig
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-28-2006, 02:10 AM
Member
 
Join Date: Apr 2006
Posts: 50
mtajim is on a distinguished road
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")
%>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
[FAQ] FileMaker Pro - database for Macintosh and Windows Martin Trautmann Tech FAQ 0 10-19-2005 12:37 AM
Comp.software-eng FAQ (Part 0): periodic postings and archives David Alex Lamb Tech FAQ 2 06-27-2004 05:15 AM
Comp.software-eng FAQ (Part 0): periodic postings and archives David Alex Lamb Tech FAQ 2 05-23-2004 05:15 AM
Comp.software-eng FAQ (Part 0): periodic postings and archives David Alex Lamb Tech FAQ 3 04-18-2004 05:15 AM
[FAQ] FileMaker Pro - database for Macintosh and Windows Martin Trautmann Tech FAQ 0 04-17-2004 07:26 AM


All times are GMT -4. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.