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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Record into access using asp

Status
Not open for further replies.

obaluba

Technical User
Sep 24, 2001
49
GB
hi.

I am trying to set a dynamic website, and would like to add the facility whereby data can be entered via a form and inserted into a database table. I have attempted to do this. I have a form that prompts the user to enter the new barcode and supplier of stationary into the stationary table. I have tryed to do this with the following code, but the ODBC error displayed is Data source name not found and no default driver specified /updatestationery.asp, line 8.

My form page is:

<% @LANGUAGE = VBScript %>

<%
If Session(&quot;Username&quot;) = &quot;noUser&quot; Then
Response.Redirect(&quot;default.asp&quot;)
End If

%>

<html>

<head>
<title>Add stationery Item</title>
</head>

<body>

<p align=&quot;center&quot;>

<b><font face=&quot;Verdana&quot; size=&quot;4&quot;>Add Stationery Item</font><font face=&quot;Verdana&quot; size=&quot;3&quot;><br>
</font></b>


<p align=&quot;center&quot;><img border=&quot;0&quot; src=&quot;images/stock.5.gif&quot;><b><font face=&quot;Verdana&quot; size=&quot;3&quot;>
<br>

</font></b></p>
<p align=&quot;center&quot;>&nbsp;</p>


<table border=&quot;0&quot; width=&quot;80%&quot; height=&quot;149&quot;>
<tr>
<td width=&quot;36%&quot; height=&quot;25&quot; align=&quot;left&quot; valign=&quot;middle&quot;>
<form ACTION=&quot;updatestationery.asp&quot; METHOD=&quot;POST&quot;>
<font face=&quot;Verdana&quot; size=&quot;3&quot;>Barcode:</font></td>
<td width=&quot;64%&quot; height=&quot;25&quot; align=&quot;left&quot; valign=&quot;middle&quot;><font size=&quot;1&quot;><input SIZE=&quot;15&quot; NAME=&quot;NewBBarcode&quot;></font></td>
</tr>
<tr>
<td width=&quot;36%&quot; height=&quot;25&quot; align=&quot;left&quot; valign=&quot;middle&quot;><font face=&quot;Verdana&quot; size=&quot;3&quot;>Supplier:
</font></td>
<td width=&quot;64%&quot; height=&quot;25&quot; align=&quot;left&quot; valign=&quot;middle&quot;><font size=&quot;1&quot;><input SIZE=&quot;15&quot; NAME=&quot;NewBSupplier&quot;></font></td>
</tr>
<tr>
<td width=&quot;40%&quot; height=&quot;63&quot; align=&quot;center&quot;>
<p align=&quot;left&quot;><input TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></td>
<td width=&quot;60%&quot; height=&quot;63&quot; align=&quot;center&quot;>
<p align=&quot;left&quot;>&nbsp;</FORM>
</td>
</tr>
</table>
</body>

</html>


The update stationary table, which is meant to insert the data into the table is as follows:

<% @LANGUAGE = VBScript %>

<%
Dim Conn
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Dim ConnectionString
Conn.ConnectionString = &quot;DSN=Tables; UID=; PWD=&quot;
Conn.Open ConnectionString

Set stationery = Server.CreateObject(&quot;ADODB.Recorset&quot;)
sSQL = &quot;SELECT * from stationery&quot;
stationery.Open, sSQL, Conn

Barcode = Request.Form(&quot;NewBBarcode&quot;)
If Len(Barcode) > 0 Then
Application.Lock
stationery.AddNew
stationery.Fields(&quot;Barcode&quot;) = Barcode
stationery.Fields(&quot;Supplier&quot;) = Request.Form(NewBSupplier)
stationery.UpdateBatch
Application.Unlock
Response.Redirect(&quot;success.asp&quot;)

ELSE Response.Redirect(&quot;fail.asp&quot;)

End If

Set objCmd = Nothing
objConn.Close
Set objConn = Nothing

%>




Can anyone figure out what is actually wrong with the code??! I would really, really, really appreciate it. Thanks.

 
try taking out the pass and userid here
Conn.ConnectionString = &quot;DSN=Tables; UID=; PWD=&quot;

try not using the same names for everything. as you have it your connection object is stationery and your table name being referenced is stationery. bad form!

_________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
there's also some missing quotes here &quot; &quot;
stationery.Fields(&quot;Supplier&quot;) = Request.Form(NewBSupplier)

try debugging routines through the entire code!
there are some good routines listed in these links
faq333-3048
faq333-2924

_________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top