Click here to Skip to main content
15,914,642 members
Home / Discussions / Database
   

Database

 
AnswerRe: Access denied - urgent [modified] Pin
S Douglas29-Jul-06 20:04
professionalS Douglas29-Jul-06 20:04 
QuestionReferential Integrity Question [modified] Pin
xfitr228-Jul-06 6:27
xfitr228-Jul-06 6:27 
AnswerRe: Referential Integrity Question Pin
ToddHileHoffer28-Jul-06 6:57
ToddHileHoffer28-Jul-06 6:57 
QuestionSQL Server Connection Pin
smarttom9928-Jul-06 5:31
smarttom9928-Jul-06 5:31 
AnswerRe: SQL Server Connection Pin
ToddHileHoffer28-Jul-06 7:00
ToddHileHoffer28-Jul-06 7:00 
QuestionCombining results of two queries Pin
coolestCoder28-Jul-06 4:19
coolestCoder28-Jul-06 4:19 
AnswerRe: Combining results of two queries Pin
ToddHileHoffer28-Jul-06 5:35
ToddHileHoffer28-Jul-06 5:35 
QuestionDatasets + Update Issue [modified] Pin
Tristan Rhodes28-Jul-06 4:07
Tristan Rhodes28-Jul-06 4:07 
I have a data structure that i am storing a set of data in, that is manipulated, before being applied to the database on calling the Save() function.

The database has a unique field, say 'Name', that is constrained as being unique.

This lead me to notice a potential problem that could affect how Datasets work, and i'd like to avoid it without having to turn off the database constraints. The problem is as follows:


Code
====

Firstly, this code is run, adding two records by name to the dataset, and then saving it to the database.
<br />
obj.Add("AAA")<br />
obj.Add("BBB")<br />
obj.Save()<br />



Database
========

After running this code, the database table will look as follows:

id name
1 AAA
2 BBB


Code
====

Then we run the following code, which loads the table, renames the two records in the dataset using a Tower of Babel kind of name swap, and saves it back to the database.

<br />
obj.Load()<br />
obj["AAA"].Name = "---"<br />
obj["BBB"].Name = "AAA"<br />
obj["---"].Name = "BBB"<br />
obj.Save()<br />


Now, at this point, when it tries to do the save, the application should fall over (Assuming i understand how datasets work)

In effect, we have swapped the two item names, "AAA" and "BBB", so we would like the table to read as follows:


Database
========
id name
1 BBB
2 AAA


However, as only two records exist in the dataset, both flagged as 'Updated', the following queries are generated:
"UPDATE SET name = 'BBB' WHERE (id = 1)"
"UPDATE
SET name = 'AAA' WHERE (id = 2)"

At which point, on executing the first query, it would attempt to update the database table to the following state:

Database
========
id name
1 BBB
2 BBB

Whereupon, it would crash, as the unique constraint is broken.


The only possible solution would be if microsoft (in all their wisdom) thought of this, and implemented some kind of update stack, which may also work, as all three updates would be applied in order, and no exceptions would be generated. (But i don't think they do as the update commands are handled by the data adapter and the rows merely have an update type indicator)

Will it work, or will in not?

Cheers guys

Tris


-- modified at 4:54 Sunday 30th July, 2006

AnswerConfirmed Pin
Tristan Rhodes31-Jul-06 0:37
Tristan Rhodes31-Jul-06 0:37 
Questionproblem with update Pin
Jeeva Mary Varghese28-Jul-06 2:13
Jeeva Mary Varghese28-Jul-06 2:13 
AnswerRe: problem with update Pin
Eric Dahlvang28-Jul-06 4:24
Eric Dahlvang28-Jul-06 4:24 
GeneralRe: problem with update [modified] Pin
Jeeva Mary Varghese28-Jul-06 20:02
Jeeva Mary Varghese28-Jul-06 20:02 
GeneralRe: problem with update Pin
Eric Dahlvang31-Jul-06 3:32
Eric Dahlvang31-Jul-06 3:32 
QuestionFirebirdSql.Data.Firebird.FbException ? Pin
nick_net128-Jul-06 1:10
nick_net128-Jul-06 1:10 
QuestionRegarding retrieve the data from two different tables Pin
ChennaiBabu28-Jul-06 1:07
ChennaiBabu28-Jul-06 1:07 
AnswerRe: Regarding retrieve the data from two different tables Pin
Mairaaj Khan28-Jul-06 2:19
professionalMairaaj Khan28-Jul-06 2:19 
AnswerRe: Regarding retrieve the data from two different tables Pin
enjoycrack29-Jul-06 6:22
enjoycrack29-Jul-06 6:22 
Question[Message Deleted] Pin
very_short_life27-Jul-06 23:17
very_short_life27-Jul-06 23:17 
AnswerRe: pleeeeeeeeeeeeeeeeeeeese help Pin
jebberwocky27-Jul-06 23:41
jebberwocky27-Jul-06 23:41 
AnswerRe: pleeeeeeeeeeeeeeeeeeeese help Pin
Hy Chanhan28-Jul-06 1:20
professionalHy Chanhan28-Jul-06 1:20 
AnswerRe: pleeeeeeeeeeeeeeeeeeeese help Pin
Ravi kumar G29-Jul-06 2:52
Ravi kumar G29-Jul-06 2:52 
AnswerRe: pleeeeeeeeeeeeeeeeeeeese help Pin
S Douglas29-Jul-06 20:36
professionalS Douglas29-Jul-06 20:36 
AnswerRe: pleeeeeeeeeeeeeeeeeeeese help Pin
Ennis Ray Lynch, Jr.31-Jul-06 8:40
Ennis Ray Lynch, Jr.31-Jul-06 8:40 
QuestionHow can I join 2 xml documents to get one table. Pin
kalyan_vb27-Jul-06 17:00
kalyan_vb27-Jul-06 17:00 
QuestionVB.NET , DATAGRID Pin
gordie warwick27-Jul-06 8:22
gordie warwick27-Jul-06 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.