|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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")), "'", "''")
|
|
#4
|
|||
|
|||
|
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) |
|
#5
|
|||
|
|||
|
thank you helping out guys.
all suggestions came out great. |
|
#6
|
|||
|
|||
|
your welcome, bulletz
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > error adding data to access DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|