Re: DataSet and updating

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 04/27/04


Date: Tue, 27 Apr 2004 14:21:38 -0400

The refresh dataset option on the configuration wizard does this for you..
nothing wrong with using a Select, it's just what you are selecting.

If you are getting it without the update, it's b/c you are trying to insert
a value into the db that isn't valid. Have you stepped through and seen what
the param values are ? If not, walk through your datatable with a
Debug.Writeline and write them out.. then verify they don't exist in the db.

Also, have you set the autoincrement property of the DataColumn to true? It
not, make sure you do it. Set the AutoINcrement Seed to 0 and the
AutoINcrementValue to -1. You may just be trying to add a value that's
already in there
"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?
> >



Relevant Pages

  • Re: Best way to generate a new unique identifier for a row insert?
    ... Set the Autoincrement property to true of the ... datacolumn you want to use. ... if you have the Refresh DataSet option set to true) and get the new value. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataSet and updating
    ... Autoincrement seed as 0 and the Autoincrement value to -1. ... guarantee that you and some other user don't step on each other. ... > The reason why I'm using a select statement is because I thought that I ... I have a table with a primary key being an integer. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Updating the correct keys
    ... > Hi Geoff, ... > Let's assume the database issues the primary keys as autoincrement values. ... > In the xsd designer, for the primary key in each table, set AutoIncrement ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: How can I get the value of an autoincremented column when adding new rows to a DataTable?
    ... set the primary key field's AutoIncrementStep and AutoIncrementSeed both ... Add code to the end of the insert statement to get back the autoincrement ... AccessFlagLookupID FROM dbo.AccessFlagLookup WHERE (AccessFlagLookupID = ... This methodology works great with SQL Server. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Primary Key as Identity column
    ... Is the column defined as the primary key in Enterprise Manager? ... having it as Autoincrement doesn't make it the primary key which may be ... confusing the SqlClient modules. ... > I am ignorant as to how I can set properties of a column in a typed ...
    (microsoft.public.dotnet.framework.adonet)