ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 15th, 2003, 04:36 AM
bulletz bulletz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 168 bulletz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 19 m 45 sec
Reputation Power: 6
error adding data to access DB

hello:
im getting an error msg everytime i try to add a data to an access db.

the error msg is:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E2F)
[Microsoft][ODBC Microsoft Access Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
/myapps/dbsite/article.asp, line 58

and the asp file is this
<%
dim adoconn
dim myquery
dim rsaddArticles

dim url
dim author
dim title
dim category
dim article

Set adoconn = Server.CreateObject("ADODB.Connection")
adoconn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("articleDB.mdb")

Set rsaddArticles = Server.CreateObject("ADODB.Recordset")

author = request.form("author")
title = request.form("title")
category = request.form("category")
article = request.form("article")
email = request.form ("email")

'Select Case request.form("category")
'Case request.form("category") = "1"
' category = "General News"
'Case request.form("category") = "2"
' category = "Sports"
'Case request.form("category") = "3"
' category = "Lifestyle"
'Case request.form("category") = "4"
' category = "Entertainment"
'Case Else
' Response.Write "choose category"
'End Select

if (author = "") or (title = "") or (category = "") or (article = "") or (email = "") then
response.write ("something is missing! kindly complete form before submitting")
else
myquery = "SELECT author,title,article,category,email FROM articles;"
rsaddArticles.CursorType = 2
rsaddArticles.LockType = 3
rsaddarticles.Open myquery, adoconn
rsaddArticles.AddNew

rsaddArticles.Fields("author") = Request.Form("author")
rsaddArticles.Fields("title") = Request.Form("title")
rsaddArticles.Fields("article") = Request.Form("article")
rsaddArticles.Fields("category") = request.form ("category")
rsaddArticles.Fields("email") = Request.Form("email")

rsaddArticles.Update
rsaddArticles.Close
Set rsaddArticles = Nothing
Set adoconn = Nothing
response.redirect "showarticles.asp"
end if

%>

the error is ponting to line 58 which is rsaddArticles.Update, i can't figure out what does it mean. can somebody explain the error just occured?

thanks any help will be appreciated

Reply With Quote
  #2  
Old December 15th, 2003, 04:50 AM
srinath srinath is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Bangalore, India.
Posts: 21 srinath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to srinath
Well,

looks like you have defined a primary key in the database. If you have a primary key defined in your database, then you shall not be able to have duplicate data in the same field. Check your database & you must be able to fix the problem..

Regards

Reply With Quote
  #3  
Old December 15th, 2003, 04:55 AM
fizzy's Avatar
fizzy fizzy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Dublin, Ireland
Posts: 100 fizzy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 5 sec
Reputation Power: 6
hi bulletz,
i'm not used to doing insert statements that way - are you sure some of your columns are not defined as primary keys?
it may not solve your problem, but if you insert data using the following method instead you may not have this problem:

Code:
SQL = "INSERT INTO articles (author,title,category,article,email) VALUES ('" & author & "','" & "','" & title & "','" & category &"','" & article & "','" & email ")"
adoConn.execute SQL


remember to do use replace on your inputs to escape apostrophes first! e.g.

Code:
author = replace(trim(Request.Form("author")), "'", "''")

Reply With Quote
  #4  
Old December 15th, 2003, 07:45 PM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 6
or u can also add another field to your access d/b with type as autonumber, that way you needn't worry about the primary key. this would be your last resort, if you still need to add all those records into your table.
__________________
Hope this helps.

Mike
Royal Selangor Pewter

"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)

Reply With Quote
  #5  
Old December 16th, 2003, 02:16 AM
bulletz bulletz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 168 bulletz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 19 m 45 sec
Reputation Power: 6
thank you helping out guys.
all suggestions came out great.

Reply With Quote
  #6  
Old December 16th, 2003, 02:18 AM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 6
your welcome, bulletz

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > error adding data to access DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT