William
Tue Apr 27 14:14:43 CDT 2004
How many rows are considered changed (Modified/Added/Deleted)? If the
rowstate for the 1st 3 is unchanged, nothing in Update should be firing for
it, so check the rowstate for each one.
"ADO.NET.Needs.Work" <anonymous@discussions.microsoft.com> wrote in message
news:4B919A02-B72E-4326-97E2-67ACA6328990@microsoft.com...
> Already did that. It adds the records to the table correctly, but once
the DataAdapter.Update command is executed, it also trys to add the records
that are already in the table.
>
> For instance, lets say I have the following table:
>
> ID title URL
> ----------------------------------------------------------------------
> 1 Microsoft
http://www.microsoft.com
> 2 Google
http://www.google.com
> 3 Experts Exchange
http://www.experts-exchange.com
>
> I use a DataAdapter.Fill to fill my dataset object.
>
> I add the following record:
>
> ID title URL
> ----------------------------------------------------------------------
> 4 Yahoo!
http://www.yahoo.com
>
> Then, I use DataAdapter.Update to send the updates to the MS SQL 7 server.
>
> If this table I just described had the exact same problem as the one I'm
developing, DataAdapter.Update will add record 4 correctly. But...once
DataAdapter.Update sees records 1, 2, and 3, it thinks they are new records,
and attempts to add them. This would bring me to the following error:
>
> Column 'id' is constrained to be unique. Value '1' is already present.
>
> So apparently, DataAdapter.Update is not using my Update statement at all.
>
> If you have any suggestions, they would be greatly appreciated.
>
> ----- William Ryan eMVP wrote: -----
>
> I posted this in another NG a few minute ago, but this is probably
the
> problem (I thought it was you but I realize it wasn't)l
>
> <<Set the Autoincrement propety of the datacolumn to true. Then set
the
> Autoincrement seed as 0 and the Autoincrement value to -1. This way,
> when -1 hits the db, SQL Server will asssign the next legit value and
> guarantee that you and some other user don't step on each other.
>
>
http://www.knowdotnet.com/articles/adopartiii.html>>
> "ADO.NET.Needs.Work" <anonymous@discussions.microsoft.com> wrote in
message
> news:1DB0FF7C-7504-4046-803B-952A1C95077B@microsoft.com...
> > The reason why I'm using a select statement is because I thought
that I
> needed it. Looking at the insert statement that was automatically
generated
> by VS.NET, this is what it contained:
> >> NSERT INTO dbo.links_page(title, imageurl) VALUES (@title,
@imageurl);
> SELECT title, link_page_id, imageurl FROM dbo.links_page
> >> Also, removing the select statement from the update statement
***does not
> work***. I still get the same error. The updated statement is
below:
> >> UPDATE dbo.links_page SET (title=@title, imageurl=@imageurl) WHERE
> (link_page_id = @link_page_id)
> >> link_page_id is my primary key.
> >> Any suggestions would be greatly appreciated.
> >>> ----- William Ryan eMVP wrote: -----
> >> That Select statement is the problem, the update fires row by
row ,
> but your
> > select is firing and returning the whole dataset not just the
row..
> so you
> > need to add a
> > WHERE ((link_page_id = @link_page_id) for instance (NOt sure
if
> that's the
> > value of your key, but you want to pull back only one record
that
> matches
> > what you updated
> >> "ADO.NET.Needs.Work" <anonymous@discussions.microsoft.com>
wrote in
> message
> > news:0FF751E7-5AF3-45B7-95A9-26F8353FCEA4@microsoft.com...
> >> Ok. I have a table with a primary key being an integer. When
> using
> > VS.NET 2002, it could not create an update command for my
table.
> Being SQL
> > savvy, I created my own update statement below:
> >>> Me.SqlCommand4.CommandText = "UPDATE dbo.links_page SET
> (title=@title,
> > imageurl=@imageurl) WHERE (link_page_id = @link_page_id);
SELECT
> title,
> > link_page_id, imageurl FROM dbo.links_page"
> >>> It is bound to the SqlDataAdapter I created. When I add a new
> record, it
> > is getting the proper auto-increment values, and when I
execute
> > ..Update(myDataSet), the record is added to the database
table.
> >>> But after that record is added, it gives me a constraint error.
> > Apparently, it is having a problem with records that are
already in
> the
> > table. It looks like it is attempting to insert copies of
them into
> the
> > table (which violates my primary key.)
> >>> The exact error is:
> >>> Column 'link_page_id' is constrained to be unique. Value '2' is
> already
> > present.
> >>> How do I fix this problem?
> >>