B
bz
Hi,
I spent several days and I cannot manage to make TableAdapters to
automatically post updates to database.
I created a typed dataset with one tableadapter
But somehow I cannot manage to update data in database.
When I call update nothing is happening.
How should I configure the tableadapter to send updates to database?
I can delete a row from tableadapter, or add a row (with Remove or Add
methods), the changes are shown in UI, but no matter how I call
Update, nothing is sent back to database, and also I don't get any
error (to tell me something is wrong). So I really don't know what to
do. I tries calling TableAdaper.Update and DataTable.AcceptChanges,
but nothing.
I understood that it is enough to call Update method, passing as
parameter either datatable or datarow the tableadapter is related to,
but it seems nothing is happening.
I have a wrapping class that has two private members, the tableadapter
and corresponding datatable.
The wrapping class provides wrapper methods around the queries I
created in dataadapter.
Load() - to load the whole dataset
Load(ID) to load a single row
Delete(ID) to delete a single row using ID
In tableadapter, I created the following queries:
1. A default query to retrieve all records:
SELECT group_id, group_name, group_descript, group_ro, group_admin,
date_created, date_updated FROM dbo.Groups
2. A delete query (with a single praameter, group_id)
DELETE FROM Groups
WHERE (group_id = @Original_group_id)
I opened the typed dataset containing this TableAdapter in design view
and I checked the properties, and I see it has set all four queries
(select, insert, update,delete)
They are below:
Select:
SELECT group_id, group_name, group_descript, group_ro,
group_admin, date_created, date_updated
FROM Groups
Update:
UPDATE Groups
SET group_name = @group_name, group_descript =
@group_descript, group_ro = @group_ro, group_admin = @group_admin,
date_created = @date_created, date_updated =
@date_updated
WHERE (group_id = @Original_group_id) AND (group_name =
@Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (@IsNull_date_updated = 1)
AND
(date_updated IS NULL) OR
(group_id = @Original_group_id) AND (group_name
= @Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (date_updated =
@Original_date_updated)
Delete:
DELETE FROM Groups
WHERE (group_id = @Original_group_id) AND (group_name =
@Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (@IsNull_date_updated = 1)
AND
(date_updated IS NULL) OR
(group_id = @Original_group_id) AND (group_name
= @Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (date_updated =
@Original_date_updated)
Insert:
INSERT INTO [Groups] ([group_name], [group_descript], [group_ro],
[group_admin], [date_created], [date_updated]) VALUES (@group_name,
@group_descript, @group_ro, @group_admin, @date_created,
@date_updated);
SELECT group_id, group_name, group_descript, group_ro, group_admin,
date_created, date_updated FROM Groups WHERE (group_id =
SCOPE_IDENTITY())
However, with this set, and the Update method of tableAdapter does
nothing
I know SQL, but those sql statements looks odd. Are they correct? Why
are they using so many parameters.
Please help, I'm getting desperate, I spent countless hours trying to
make this work
Thank you
I spent several days and I cannot manage to make TableAdapters to
automatically post updates to database.
I created a typed dataset with one tableadapter
But somehow I cannot manage to update data in database.
When I call update nothing is happening.
How should I configure the tableadapter to send updates to database?
I can delete a row from tableadapter, or add a row (with Remove or Add
methods), the changes are shown in UI, but no matter how I call
Update, nothing is sent back to database, and also I don't get any
error (to tell me something is wrong). So I really don't know what to
do. I tries calling TableAdaper.Update and DataTable.AcceptChanges,
but nothing.
I understood that it is enough to call Update method, passing as
parameter either datatable or datarow the tableadapter is related to,
but it seems nothing is happening.
I have a wrapping class that has two private members, the tableadapter
and corresponding datatable.
The wrapping class provides wrapper methods around the queries I
created in dataadapter.
Load() - to load the whole dataset
Load(ID) to load a single row
Delete(ID) to delete a single row using ID
In tableadapter, I created the following queries:
1. A default query to retrieve all records:
SELECT group_id, group_name, group_descript, group_ro, group_admin,
date_created, date_updated FROM dbo.Groups
2. A delete query (with a single praameter, group_id)
DELETE FROM Groups
WHERE (group_id = @Original_group_id)
I opened the typed dataset containing this TableAdapter in design view
and I checked the properties, and I see it has set all four queries
(select, insert, update,delete)
They are below:
Select:
SELECT group_id, group_name, group_descript, group_ro,
group_admin, date_created, date_updated
FROM Groups
Update:
UPDATE Groups
SET group_name = @group_name, group_descript =
@group_descript, group_ro = @group_ro, group_admin = @group_admin,
date_created = @date_created, date_updated =
@date_updated
WHERE (group_id = @Original_group_id) AND (group_name =
@Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (@IsNull_date_updated = 1)
AND
(date_updated IS NULL) OR
(group_id = @Original_group_id) AND (group_name
= @Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (date_updated =
@Original_date_updated)
Delete:
DELETE FROM Groups
WHERE (group_id = @Original_group_id) AND (group_name =
@Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (@IsNull_date_updated = 1)
AND
(date_updated IS NULL) OR
(group_id = @Original_group_id) AND (group_name
= @Original_group_name) AND (group_ro = @Original_group_ro) AND
(group_admin = @Original_group_admin) AND
(date_created = @Original_date_created) AND (date_updated =
@Original_date_updated)
Insert:
INSERT INTO [Groups] ([group_name], [group_descript], [group_ro],
[group_admin], [date_created], [date_updated]) VALUES (@group_name,
@group_descript, @group_ro, @group_admin, @date_created,
@date_updated);
SELECT group_id, group_name, group_descript, group_ro, group_admin,
date_created, date_updated FROM Groups WHERE (group_id =
SCOPE_IDENTITY())
However, with this set, and the Update method of tableAdapter does
nothing
I know SQL, but those sql statements looks odd. Are they correct? Why
are they using so many parameters.
Please help, I'm getting desperate, I spent countless hours trying to
make this work
Thank you