Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 12th, 2004, 06:27 PM
Registered User
 
Join Date: May 2004
Location: , KS, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setup ???

I'm 100% new to ASP pages but familuar with HTML.

I'm having trouble with a couple pages i've made to update a database and so I have a few questions I need answered and depending on the answer I may need a few more :P

I made a phonebook, access database with 3 fields, Name, Number, Notes. The database is named db2.

1. When I try to add a entry to my database I get a error but I'm almost certain there is nothing wrong with my code. I'm wondering if I need to enable something on the server to get ASP pages to update a database ?

Error:
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Click the Refresh button, or try again later.

Open the ts-sql home page, and then look for links to the information you want.
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
/db2/new.asp, line 14


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

Page:
POST 23 bytes to /db2/new.asp

POST Data:
Name=1&Notes=1&Number=1

Time:
Wednesday, May 12, 2004, 6:23:36 PM


More information:
Microsoft Support

Code:
<%
if request.form.count<>0 then
strError = "" 'set a clear error message
if request.form("Name") ="" then strError = "You did not enter a name in the form" & "<BR>"
if request.form("Number") = "" then strError = "You did not enter a number in the form "
if strError="" then
' tblPb Name, Number, Notes
Set Con = Server.CreateObject("ADODB.Connection")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db2.mdb") & ";Persist Security Info=False"
Con.Mode = 3
Con.Open strConn, "",""
strSQL = "INSERT INTO tblPB (Name, Number, Notes) values ('" & request.form("Name") & "', '" & request.form("Number") & "', '" & request.form("Notes") & "');"
response.write "<p>" & strSQL
Con.Execute(strSQL)
Set Con = Nothing
end if ' no error message
end if ' did the form post?
%>

<head>
<title>New Record</title>
</head>
<body>
<p>&nbsp;</p>
  <form name="addNew" action="new.asp" method="post">

<div align="center">
  <center>
<% if strError<>"" then response.write "<p><b>" & strError & "</b></p>" %>

  <table border=0 cellspacing=0 cellpadding=0 bgcolor="#e6e6e6" style='background:
 #E6E6E6;border-collapse:collapse;mso-padding-alt:0in 5.4pt 0in 5.4pt'>
    <tr>
      <td width=148 valign=top bordercolor="#808080" bgcolor="#808080"><p><b><span style='color:red'>*</span>Name:</b></p></td>
      <td width=295 valign=top bordercolor="#808080" bgcolor="#808080"><p><b>Notes:</b></p></td>
      <td width=148 valign=top bordercolor="#808080" bgcolor="#808080"><p><b></b></p></td>
    </tr>
    <tr>
      <td width=148 valign=top><p>
          <input type="text" name="Name" size="25" value="<%=request.form("Name")%>">
      </p></td>
      <td width=295 colspan=2 rowspan=3 valign=top><p>
          <textarea name="Notes" cols=40 rows=3 wrap="virtual"> <%=request.form("Notes")%></textarea>
        </td>
    </tr>
    <tr>
      <td width=148 valign=top bgcolor="#808080"><p><b><span style='color:red'>*</span>Number:</b></p></td>
    </tr>
    <tr>
      <td width=148 valign=top><p>
          <input type="text" name="Number" size="25" value="<%=request.form("Number")%>">
      </p></td>
    </tr>
    <center>
    </center>
  </table>
</div>

<p>&nbsp;<center><INPUT TYPE="submit" VALUE="Submit"> &nbsp;&nbsp; <INPUT TYPE="reset" VALUE="Reset"></center></p>
</form>

</body>




Reply With Quote
  #2 (permalink)  
Old May 12th, 2004, 07:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

To me, your query looks fine: "INSERT INTO tblPB (Name, Number, Notes) values ('" & request.form("Name") & "', '" & request.form("Number") & "', '" & request.form("Notes") & "');"

However, the Number field, is it stored as a number in the database? If so, it shouldn't have single quotes around it?

Brian
Reply With Quote
  #3 (permalink)  
Old May 13th, 2004, 06:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try to put Response.END after these lines

strSQL = "INSERT INTO tblPB (Name, Number, Notes) values ('" & request.form("Name") & "', '" & request.form("Number") & "', '" & request.form("Notes") & "');"
response.write "<p>" & strSQL
Response.END

Copy the output of strSQL and execute it directly in your database and see what it ERRs. That would help you better.

Cheers!

-Vijay G
Reply With Quote
  #4 (permalink)  
Old May 13th, 2004, 10:52 AM
Registered User
 
Join Date: May 2004
Location: , KS, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,
Actually all fields are text...

Hi Vijay,
I tried the Response.END, I'm not sure what that got me other than showing that it does seem to work. I put in Name, Number and Notes for the fields and this is what I see on the screen...
INSERT INTO tblPB (Name, Number, Notes) values ('Name', 'Number', 'Notes');

What I'm not too sure about is "execute it directly in your database". I'm not sure how to go about doing that.


Reply With Quote
  #5 (permalink)  
Old May 13th, 2004, 11:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Open you database file in MSAccess.

Click "Queries" tab, create new query in "Design View", it would ask you to add the table involved, in your case "tblPB". You would see that added to the design window behind it, Then close the "Add Table" window. From View Menu, Choose "SQL" and replace whatever query it shows there by pasting the following one. Now execute it by clicking the "!" mark in the TOOLBAR above.

See what error it throws and post the same here to get better help.

INSERT INTO tblPB (Name, Number, Notes) values 'Name', 'Number', 'Notes');

Hope I have not missed anything in the process. All the best;).
Cheers!

-Vijay G
Reply With Quote
  #6 (permalink)  
Old May 13th, 2004, 11:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

There was a bracket missing in the one I posted before this.

INSERT INTO tblPB (Name, Number, Notes) values('Name', 'Number', 'Notes');

Pls use the one you got from your
response.write "<p>" & strSQL

-Vijay G
Reply With Quote
  #7 (permalink)  
Old May 13th, 2004, 12:51 PM
Registered User
 
Join Date: May 2004
Location: , KS, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Vijay, your solution was the answer to finding the cure !!!

The message wasn't anything special, at first I lost heart but when I hit ok, it would highlight the word Number...

I checked the field and everything was spelled correct so I didn't grasp the importance at first but eventually the lights came on and I could see...

It appears Number is a special "keyword" and once I changed all references from number to num it Worked !!!! I would guess this is a keyword for ASP insert into statement but more research may be necessary to be sure.

Thanks for your help !!!

-Orko-

Reply With Quote
  #8 (permalink)  
Old May 14th, 2004, 07:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Oh. Sorry about that. While reading your post I noticed that you have given one of your column's name as NUMBER, which is a reserved keyword in ACCESS. NUMBER is a datatype in access. So you should not have used that as a FIELDName.

But I can give you a work around, put a [] around the NUMBER, if you have to make changes in your code.

-Vijay G
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to setup FCKEDITOR?? stzd8 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 December 12th, 2006 11:27 AM
installation setup ! anukagni Access 1 October 18th, 2006 06:54 AM
SetUp calvados Pro VB.NET 2002/2003 2 December 30th, 2004 04:12 AM
help me with the setup cpux00 ASP.NET 1.0 and 1.1 Professional 1 July 22nd, 2003 02:13 PM
Page setup thutt Access 1 June 17th, 2003 07:50 AM



All times are GMT -4. The time now is 11:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.