Re: DataSet and updating
From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 04/27/04
- Next message: William Ryan eMVP: "Re: DataSet and updating"
- Previous message: William Ryan eMVP: "Re: DataView.Sort loses ASC/DESC value"
- In reply to: ADO.NET.Needs.Work: "Re: DataSet and updating"
- Next in thread: William Ryan eMVP: "Re: DataSet and updating"
- Messages sorted by: [ date ] [ thread ]
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?
> >
- Next message: William Ryan eMVP: "Re: DataSet and updating"
- Previous message: William Ryan eMVP: "Re: DataView.Sort loses ASC/DESC value"
- In reply to: ADO.NET.Needs.Work: "Re: DataSet and updating"
- Next in thread: William Ryan eMVP: "Re: DataSet and updating"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|