PC Review


Reply
Thread Tools Rate Thread

Access Update() Duplicate Exception

 
 
=?Utf-8?B?U3RldmUgQi4=?=
Guest
Posts: n/a
 
      3rd Jan 2005
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
 
Reply With Quote
 
 
 
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      3rd Jan 2005
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." <(E-Mail Removed)> wrote in message
news:03FB19F5-65B7-45D8-B94E-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
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." <(E-Mail Removed)> wrote in message
news:03FB19F5-65B7-45D8-B94E-(E-Mail Removed)...
>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



 
Reply With Quote
 
=?Utf-8?B?U3RldmUgQi4=?=
Guest
Posts: n/a
 
      3rd Jan 2005
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

 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
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." <(E-Mail Removed)> wrote in message
news:C515624E-66CA-4C39-B84D-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?U3RldmUgQi4=?=
Guest
Posts: n/a
 
      3rd Jan 2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception - (duplicate entry that are not matching) Dan Microsoft Access Queries 4 19th Mar 2009 09:35 PM
Re: Update Exception W.G. Ryan [MVP] Microsoft ADO .NET 1 18th Jan 2007 02:24 PM
How do I catch duplicate record exception? Hexman Microsoft VB .NET 3 22nd Aug 2006 01:14 PM
MS Access VBA After update Prevent Duplicate Entry bbcdancer@hotmail.com Microsoft Access Form Coding 1 22nd Jun 2006 05:59 PM
Duplicate record with wrong exception =?Utf-8?B?VGhhbmEgTi4=?= Microsoft ADO .NET 5 25th Mar 2005 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:40 PM.