Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP add data to access question
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP add data to access question

 Post Reply Post Reply
Author
eddyb View Drop Down
Newbie
Newbie


Joined: 06 August 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote eddyb Quote  Post ReplyReply Direct Link To This Post Topic: ASP add data to access question
    Posted: 06 August 2003 at 7:50am

I have set up a access database which I want to add data to using ASP. I followed the tutorial at http://www.webwiz.net/asp/tutorials/add_to_database.asp and it works fine.

The problem is that if you dont enter text into all of the fields then it crashes and doesn't work. How can I change it so it still works even if not all the fields are filled in?

I have a database which has about 60 fields and is 10mb with no records. Am I going to run into file size problems. About 120 records will be added to it using the asp form. (the form from the above tutorial)

Many Thanks,

Ed

Back to Top
PaulGQ View Drop Down
Newbie
Newbie
Avatar

Joined: 11 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote PaulGQ Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2003 at 12:27pm

In access, just make sure the "required property" is net to no in each field.

That usually does it.

That amount of data is fine with access, buy at 50,000 records, I would then look into a sql server.

Also try to run it on a dual p3 machine or better with a gig or ram and a 15krpm hard drive.

Back to Top
eddyb View Drop Down
Newbie
Newbie


Joined: 06 August 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote eddyb Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 1:44am

Hi,

Thanks, but the 'require property' is not in the script. Do I need to put it in then set it to no?

The code for the asp is:

<%
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rsAddComments   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")

'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tbdata.name, tbdata.company, tbdata.date, tbdata.staff FROM tbdata;"

'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3

'Open the recordset with the SQL query
rsAddComments.Open strSQL, adoCon

'Tell the recordset we are adding a new record to it
rsAddComments.AddNew

'Add a new record to the recordset
rsAddComments.Fields("name") = Request.Form("name")
rsAddComments.Fields("company") = Request.Form("company")
rsAddComments.Fields("date") = Request.Form("date")
rsAddComments.Fields("staff") = Request.Form("staff")

'Write the updated recordset to the database
rsAddComments.Update

'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing

'Redirect to the guestbook.asp page
Response.Redirect "thanks.htm"
%>

Thanks,  Ed

Back to Top
PaulGQ View Drop Down
Newbie
Newbie
Avatar

Joined: 11 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote PaulGQ Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 1:47am

no, in the access database itself.

just code the script normally.  The error ison the access side, not the script side.  It is access that generates the eorror and passes it back to the browser.

 

Or you could lalways add code that adds a blank space to any firled that is empty.  But work on the access side, that is better.

Back to Top
eddyb View Drop Down
Newbie
Newbie


Joined: 06 August 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote eddyb Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 1:57am

I checked the database and the required settings are already set to no. A copy of the form can be found at:

http://www.webwiz.net/asp/tutorials/guestbook/guestbook_form.htm

Note if you only fill in one feild it is not added to the database.

 

Cheers,

Ed

Back to Top
PaulGQ View Drop Down
Newbie
Newbie
Avatar

Joined: 11 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote PaulGQ Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 2:17am

here use this. 3 part form.  never do it all in one page.

first the form.asp pointing to the processor with this

<form action=formProcessor.asp>

 

now for formprocessor.asp - this is the whole thing

<%
Comments = Request.Form("Comments")
Name = Request.Form("Name")
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DBQ=" & Server.Mappath("Database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
SQLstmt = "INSERT INTO tblName (Comments, Name)values('" & Comments & "', '" & Name & "')"
Set RS = Conn.Execute(SQLStmt)
conn.Close
Set conn = Nothing
%>

<META HTTP-EQUIV=REFRESH CONTENT="0;URL=ThankYouPage.asp">

thats it, very simple.

 

make sure you write a thank you page or it will error out.

 

 

 

Back to Top
PaulGQ View Drop Down
Newbie
Newbie
Avatar

Joined: 11 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote PaulGQ Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 2:30am

also, let me know if you ever want those results posted in the database and mailed somewhere all in one stroke.

 

 

Back to Top
eddyb View Drop Down
Newbie
Newbie


Joined: 06 August 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote eddyb Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 2:34am

I think I found the problem. I had the database set to not allow zero strings as a responce. I have changed this and am downloading my database now to make sure it all went in OK.

If this works, I will be using the orginal script. Is there any benefit changing to the one you suggested?

Also I would be interested in having the results mailed to me as you suggested. How is this achieved?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.