473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access Update() Duplicate Exception

A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)" for
the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying, in
affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve
Nov 16 '05 #1
5 2371
You're going to have to look at the Update code that you are sending back -
see what the proposed values vs the original values were and hunt it down
from there. It could be something with your uupdate command - or your app
could be modifiying a value it shouldn't be.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Steve B." <St****@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)" for the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying, in affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve

Nov 16 '05 #2
As Bill suggested, look at the command being sent back.

BTW, try doing a fillschema on your ds before doing a fill. That *might* fix
it, though that'd be in my eyes a very inefficent and bad solution - not to
mention the automatic command population is a real inefficient pig to start
with.

The best approach is to specify your own UpdateCommand so you have control
on what you're doing.

However since you are using Access, I am lead to believe that this is a one
user one d/b or close to it kind of situation, so you might even get away
with FillSchema only.

Anyway, give it a try and yes, you need to look at the command.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)"
for
the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying,
in
affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve

Nov 16 '05 #3
Thank you

1. How do I look at the Update code I’m sending back??

//my code
if (dataSet.HasChanges(DataRowState.Modified))
{
conn.Open();
//entire ds, not getChanges()
dataAdapter.Update(dataSet, tableName); //entire ds
conn.Close();
}

2. I’m looking into fillshema command now

//my code
setDataSetConstraintsOff(tempDataSet);
openDbConnection(configMgmtLogConn);
dbAdapter.Fill(dataSet);
setDataSetConstraintsOn(tempDataSet);
closeDbConnection(configMgmtLogConn);

Most everything is done through a Interface. If I change the Access Indexed
Field Property to “No” I don’t get the exception
"Steve B." wrote:
A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)" for
the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying, in
affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve

Nov 16 '05 #4
Answer to #1 -- dataAdapter.UpdateCommand.CommandText.

Answer to #2 --
Not sure why are you disabling the constraints, is it for performance??
How much data are you filling? You will have a bigger performance chunk by
specifying your own UpdateCommand if the data being filled isn't > 100ish
rows (well the rowsize matters too). FillSchema is simply
dbAdapter.FillSchema, but the dataset constraints might contradict with
that, since those are counter intuitive to FillSchema. Also what process is
setting the dataset constraints in the first place before you call
setDataSetConstraintsOff

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


"Steve B." <St****@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Thank you

1. How do I look at the Update code I'm sending back??

//my code
if (dataSet.HasChanges(DataRowState.Modified))
{
conn.Open();
//entire ds, not getChanges()
dataAdapter.Update(dataSet, tableName); //entire ds
conn.Close();
}

2. I'm looking into fillshema command now

//my code
setDataSetConstraintsOff(tempDataSet);
openDbConnection(configMgmtLogConn);
dbAdapter.Fill(dataSet);
setDataSetConstraintsOn(tempDataSet);
closeDbConnection(configMgmtLogConn);

Most everything is done through a Interface. If I change the Access
Indexed
Field Property to "No" I don't get the exception
"Steve B." wrote:
A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)"
for
the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying,
in
affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve

Nov 16 '05 #5
The constraints were from another program I templated from. I’ve commented
them out for now. There are 1000 rows and about 16 columns.

The column I’m having the problem with is DocumentNumber. I also looked at
the VS SQL Builder. I'm just going to have to walk through the column and
declare the Indexed field as "No"

UPDATE StevesConfigMgmtLog
SET
[Acceptance(Y/N)] = ?,
ClassType = ?,
DateIn = ?,
DateOut = ?,
DCM_NDTApproved = ?,
DocumentNumber = ?,
DocumentType = ?,
Engine = ?,
Engineer = ?,
ErrorCategory = ?,
[GE_CauseCode/Type] = ?,
[IsCSI?] = ?,
Purpose = ?,
Remarks = ?,
ReviewerCauseCode = ?,
Subject = ?

WHERE
(ID = ?) AND
([Acceptance(Y/N)] = ? OR ? IS NULL AND [Acceptance(Y/N)] IS NULL) AND
(ClassType = ? OR ? IS NULL AND ClassType IS NULL) AND
(DCM_NDTApproved = ? OR ? IS NULL AND DCM_NDTApproved IS NULL) AND
(DateIn = ? OR ? IS NULL AND DateIn IS NULL) AND
(DateOut = ? OR ? IS NULL AND DateOut IS NULL) AND
(DocumentNumber = ? OR ? IS NULL AND DocumentNumber IS NULL) AND
(DocumentType = ?) AND (Engine = ? OR ? IS NULL AND Engine IS NULL) AND
(Engineer = ? OR ? IS NULL AND Engineer IS NULL) AND
(ErrorCategory = ? OR ? IS NULL AND ErrorCategory IS NULL) AND
([GE_CauseCode/Type] = ? OR ? IS NULL AND [GE_CauseCode/Type] IS NULL) AND
([IsCSI?] = ? OR ? IS NULL AND [IsCSI?] IS NULL) AND
(Purpose = ? OR ? IS NULL AND Purpose IS NULL) AND
(Remarks = ? OR ? IS NULL AND Remarks IS NULL) AND
(ReviewerCauseCode = ? OR ? IS NULL AND ReviewerCauseCode IS NULL) AND
(Subject = ? OR ? IS NULL AND Subject IS NULL)

"Steve B." wrote:
A particular column in my Access DB table, and the associated datagrid,
cannot have duplicate string entries. I've selected "Yes (no duplicates)" for
the Indexed Field Property of this column in the Access table.

When I call update(), the DB gets updated but throws an exception saying, in
affect, that I'm trying to change the key. This column is not the key.

How do I handle this? How do I stop the ex.message being thrown?

I guess I could always walk through the column searching for the value.

Steve

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
wondered if anyone might lend a hand? I'm having a little difficulty updating the backend SQL Server tables. Normally I just use Access' update but I'd really like to try something new. I'd like...
0
by: Mitja Semolic | last post by:
Deploying ASP.NET web sites to Windows 2003 Server a Nightmare! You finished implementing a ASP.NET web site and then comes the really painful part, you have to deploy it. And to make things...
1
by: spicyz | last post by:
I'm receiving an exception when my webmethod exits after opening/closing an Access database. I can reproduce this easily enough by creating a new default ASP .NET Web Service in VS.NET 2003. ...
9
by: vijayk | last post by:
Hi I have a table like the one below Pkey Sno ----------------- AA 0 BB 0 CC 0 AA 0
0
by: brads745678 | last post by:
Hi, I am having a problem with my VB .NET application. I am trying to do the most simplest of things, and I've even achieved this task before. All I am trying to do is update an access DB from VB...
2
by: patelxxx | last post by:
Guy's, Every time I update my FAQ section of the website A with new articles, I want it to update/duplicate this on my other website B. In other words when I add or edit an article in the FAQ...
6
by: bobh | last post by:
Hi All, I'm looking for help with what the Transact SQL code is for this Access Update query sql code. I've been doing Access for some time and all my back-ends have been jet. I'm just starting...
4
by: shodan | last post by:
Hi board, I'm using excel vba to drive my access database. Now I encountered the following problem: I have an update qry to update a table which has an index field. Because of this, I always...
1
praclarush
by: praclarush | last post by:
I'm trying to connect to a access database and post an update to a row in a table though code with Visual Basic 2005, but when I do, I'm getting a Syntax error with the update statment. I don't...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.