Alright, I found the solution. I had to set the relations
as such:
"Both Relation and Foreign Key constraint"
Accept/Reject rule to None
Uncheck "Nested Relation"
And problem goes away.
-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On Behalf Of
Chris Bordeman
Sent: Wednesday, November 22, 2006 9:22 AM
To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] updating child records in a
DataSet w/
new autoinc values after parent insert?
Thanks very much for replies, Vince. Unfortunately GUIDs
are not an
option.
I'd really like to solve the original problem w/ the
RowState of the
child rows being changed from Added to Modified. I'm going
to try some
workarounds, maybe save and restore the RowStates or
disabling cascades
temporarily, then following them myself to make the child
updates.
Thanks again Vince, I really appreciate your input.
Chris B.
-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On Behalf Of
Vince P
Sent: Wednesday, November 22, 2006 5:31 AM
To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] updating child records in a
DataSet w/
new autoinc values after parent insert?
I have a little time now.
If you use a uniqueidentifier type instead of an int with
identity this
allows you the same type of random assignment of a value for
the
purposes of getting a PK and it allows you to assign the
value at either
the client or server level without the need to re-update the
client with
the value (the problem you're facing with the Identity).
The uniqueidentifier column is a GUID. You can assign it at
the client
by using the Guid.NewGuid() method in the .Net Framework,
and you can
assign it at the db server by adding "NewID()" as
the default value of
the column , this way if anything adds a row to your table
without that
column given a value,a value will be made for you,
otherwise the db
will happily accept the value given to it.
As long as humans aren't viewing/processing the int value of
the old
int-identity column, this is completely seemless to users.
-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On Behalf Of
Vince P
Sent: Tuesday, November 21, 2006 2:40 PM
To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] updating child records in a
DataSet w/
new autoinc values after parent insert?
I don't have time to give you the details, I'll just paste
this from the
docs and you'll have to explore it on your own
An alternative to using an auto incrementing value is to use
the NewGuid
method of a Guid object to generate a GUID, or globally
unique
identifier, on the client computer that can be copied to the
server as
each new row is inserted. The NewGuid method generates a
16-byte binary
value that is created using an algorithm that provides a
high
probability that no value will be duplicated. In a SQL
Server database,
a GUID is stored in a uniqueidentifier column which SQL
Server can
automatically generate using the Transact-SQL NEWID()
function. Using a
GUID as a primary key can adversely affect performance. SQL
Server 2005
introduces support for the
NEWSEQUENTIALID() function, which generates a sequential
GUID that is
not guaranteed to be globally unique but that can be indexed
more
efficiently.
> -----Original Message-----
> From: Discussion forum for developers using Windows
Forms to build
> apps and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On
> Behalf Of Chris Bordeman
> Sent: Tuesday, November 21, 2006 2:32 PM
> To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-WINFORMS] updating child records
in a DataSet w/
> new autoinc values after parent insert?
>
> What does that mean?
>
> -----Original Message-----
> From: Discussion forum for developers using Windows
Forms to build
> apps and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On
> Behalf Of Vince P
> Sent: Tuesday, November 21, 2006 2:24 PM
> To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-WINFORMS] updating child records
in a DataSet w/
> new autoinc values after parent insert?
>
> Use GUIDs/uniqueidentifier instead.
>
> > -----Original Message-----
> > From: Discussion forum for developers using
Windows Forms to build
> > apps and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On
> > Behalf Of Chris Bordeman
> > Sent: Tuesday, November 21, 2006 2:16 PM
> > To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
> > Subject: Re: [DOTNET-WINFORMS] updating child
records in a
> DataSet w/
> > new autoinc values after parent insert?
> >
> > I was actually looking for something more
generalized.
> >
> > I ended up setting cascading updates and deletions
on the relations.
> > The problem there is that when the parent table is
updated not only
> > does it update the child records, it also sets
their state to
> > 'Modified.'
> > This is a big problem because their state was
initially
> 'Added.' So
> > now when I use the data adapter to update the
child table, I get
> > concurrency errors saying the record could not be
modified. Of
> > course, it was never added to the database!
> >
> > Any ideas?
> >
> > -----Original Message-----
> > From: Discussion forum for developers using
Windows Forms to build
> > apps and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On
> > Behalf Of Phil Sayers
> > Sent: Tuesday, November 21, 2006 10:59 AM
> > To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
> > Subject: Re: [DOTNET-WINFORMS] updating child
records in a
> DataSet w/
> > new autoinc values after parent insert?
> >
> > hook into the dataadapter events...
> > i forget the name. but something like the
"Updated" event is a good
> > spot.
> > in there take the new PK value from the parent
row, and
> update all of
> > it's child rows with the new value.
> > now when the dataadapter starts inserting the
child rows they will
> > have the correct reference to the parent.
> >
> >
> > -----Original Message-----
> > From: Discussion forum for developers using
Windows Forms to build
> > apps and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM]On
> > Behalf Of Chris Bordeman
> > Sent: Tuesday, November 21, 2006 11:43 AM
> > To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
> > Subject: [DOTNET-WINFORMS] updating child records
in a
> DataSet w/ new
> > autoinc values after parent insert?
> >
> >
> > Hi all. Using Dot Net 2.0.
> >
> > I have a TYPED dataset generated by VS. It
contains a parent and a
> > child table with a relationship set up in the
MSSQL database and
> > showing in the dataset. BOTH tables have new
records that
> need to be
> > added to database.
> >
> > I'm able to retrieve the server's autoinc values
on the
> parent table,
> > but I can't seem to get my data adaper to filter
the new autoinc
> > values down to the foreign key field in the child
table.
> >
> >
> > HOW EXACTLY IS THIS DONE???
> >
> >
> >
> > I'm currently doing 3 things:
> > 1. Added an output parameter to the insert
command to grab the new
> > autoinc value and feed it into my autoinc field.
> > 2. Set insertCommand.UpdatedRowSource =
> UpdateRowSource.Both (figure
> > good idea to grab it all).
> > 3. Appended " SELECT " +
identityColumn.ColumnName + " =
> > SCOPE_IDENTITY()" to the insert command.
> >
> > Does #3 keep the entire column's values from being
fed back to the
> > DataTable row?
> >
> > Do I need to AcceptChanges?
> >
> > What about if the operation fails and the
transaction is
> rolled back,
> > how do I undo changes made to the dataset?
> >
> > THANKS!!!
> >
> > Chris B.
|