Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp & sql connection

Status
Not open for further replies.

Rosee

IS-IT--Management
Dec 12, 2001
187
US
Does any out there know how to make connection on the system in order to retrive data online using ASP files? I went some related web sites and am still not clear about what to do. SQL database and ASP are both ready on the system. How can I use them more efficiantely? Example, I put a form on the web asking user to fill first name and last name, then how to use those data to find record from SQL database. In the ASP file, how to get the online info, pass to database, then display the specific record back online? THANKS.


 
Hi

Here is an example

<html><body>
<%
dim strName, strBirthdate

strName = Request.Form (&quot;Fname&quot;)
strBirthdate = Request.Form (&quot;birthdate&quot;)


' if both are blank then show the form
' if they have values but are incorrect then show form with values
' if all correct then go to the add member to db page
if (strName =&quot;&quot; and strBirthdate=&quot;&quot;) then

call show_form()
elseif (strName<>&quot;&quot; and strBirthdate<>&quot;&quot;) then
if strName = &quot;&quot; or not isdate (strBirthdate) then
Response.Write &quot;Some data in error&quot;
show_form()
end if

else
insert_data()
end if

SUB show_form()%>
<form name = entry action = formpage.asp method = post>
Name: <input name = Fname value = &quot;<%=strName%>&quot; type = text size = 20>
Birthdate: <input name = birthdate value =&quot;<%=strBirthdate%>&quot; type = text size = 10>
<input type = submit value = submit></form><%
END SUB
%>
<%
SUB insert_data()
'post the data to the database
'you will need to adjust this to match your DB setup
set objCN = server.CreateObject (&quot;adodb.connection&quot;)
strConn =&quot;DSN=lynnsDB&quot;

'&quot;DSN=LynnsDB;DBQ=C:\Inetpub\ Access;MaxBufferSize=2048;PageTimeout=5;&quot;

'create the recordset and the SQl statement, then hit the DB
set objRS = server.CreateObject (&quot;adodb.recordset&quot;)

'create the SQL statement to update the DB
strSQL = &quot;insert (name, birthdate) into mytable values(strName, strBirthdate)&quot;

objCN.Open strConn
set objRS.ActiveConnection=objCN
objRS.open strSQL

%>
</body></html>

this will give you some of the basics of what you are looking for. You can add a section to call the data back from the DB to put the data back in the form.


hth

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Thanks, Bastien.

Question about insert_data():

1. I don't have Access application on my computer. I have tried DSN using MS SQL drive and don't think it is working.
Do I have to have xxxxx.mdb connection to make ASP page works?

2. strConn=&quot;DSN=????&quot; what need to be here? database's name or table's name?

3. what is DBQ?

4. I have a database named &quot;ABC&quot; and a table named &quot;Users&quot;. How do I mention those names in the ASP file so that system would know where the data needs to go?

I am very confused about strConn, DSN, DBQ, and ADODB.Connection. Any information and help would be appreciated.

Happy Holidays!!! :cool:
 
hi

1. what database are you using? does it reside on your local machine and can you access it? What development environment are you using? Interdev / Macromedia Ultradev /something else? Most of the IDEs (integrated design envirnments) have a rapid connection feature that wil allow you to create a link to a D easily.

2. DB name

3. This was created by the DB connection setup in my IDE, refers to the physical location of the DB.

4. This is about how to connect to the DB. You have to create a connection (strConn) which hold the connection string and method, (DSN which is a DB name created on the server or DSNless which uses the driver of the DB to connect) The best thing to do is get a book, Sam's ASP in 24 Hours is a good start or Sam's ASP in 21 Days are god bets. These books will get you up to speed in no time.

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top