Odd DataAdapter ?

  • Thread starter Thread starter katie s
  • Start date Start date
K

katie s

Is there a way to force a sqldataadapter to insert the contents of a dataset
just filled into another table for example

sqlDataAdapter1.Fill(dsLabels1);
sqlDataAdapter2.Fill(dsLabels1);
sqlDataAdapter1.Update(dsLabels1);
sqlDataAdapter2.Update(dsLabels1);
???

I thought I could use this but none of the records are dirty after a fill
and I can't do this on the database side.
 
You'll need to change the AcceptChangesDuringFill property to False on both
of the dataadapters. I have a walkthrough here
http://www.knowdotnet.com/articles/datasetmerge.html but that's all you'll
need to do. Then the rowstate will be inserted and as long as your insert
command is valid, you're good to go.

Let me know if you have any questions.

Bill
 
Actually I think I've run into a problem see my data is related and I'm
getting an error... Insert statement conflicted with foreign key constraint.
Now I know why I'm getting the error and that is because I'm not making a
perfect copy.



See I'm inserting into a destination table that already has data so I can't
copy the CompanyID since it might already exist in the destination table so
the copy fails on the table "tblPeople".


tblCompany
--
CompanyID | Company | City | State
--

CREATE PROCEDURE tblCompanyInsert
(
@Company nvarchar(50),
@City nvarchar(50),
@State nvarchar(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO dbo.tblCompany(Company, City, State) VALUES (@Company, @City,
@State);
SELECT ID, Company, City, State, FROM dbo.tblOLCompany WHERE (ID =
@@IDENTITY)
GO

tblPeople
--
ID | CompanyID | Name
--

CREATE PROCEDURE tblPeople
(
@CompanyID int,
@name nvarchar(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO dbo.tblPeople(CompanyID, Name) VALUES (@CompanyID, @name);
SELECT ID, CompanyID, Name FROM dbo.tblPeople WHERE (ID = @@IDENTITY)
GO

I know I'm close but I've just been looking at this too long and I'm going
cross-eyed

Any Ideas ????

--
Kate

William Ryan eMVP said:
You'll need to change the AcceptChangesDuringFill property to False on both
of the dataadapters. I have a walkthrough here
http://www.knowdotnet.com/articles/datasetmerge.html but that's all you'll
need to do. Then the rowstate will be inserted and as long as your insert
command is valid, you're good to go.

Let me know if you have any questions.

Bill
 
Never mind I figured it out now I just need a day at the beach :)

--
Kate


katie s said:
Actually I think I've run into a problem see my data is related and I'm
getting an error... Insert statement conflicted with foreign key constraint.
Now I know why I'm getting the error and that is because I'm not making a
perfect copy.



See I'm inserting into a destination table that already has data so I can't
copy the CompanyID since it might already exist in the destination table so
the copy fails on the table "tblPeople".


tblCompany
--
CompanyID | Company | City | State
--

CREATE PROCEDURE tblCompanyInsert
(
@Company nvarchar(50),
@City nvarchar(50),
@State nvarchar(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO dbo.tblCompany(Company, City, State) VALUES (@Company, @City,
@State);
SELECT ID, Company, City, State, FROM dbo.tblOLCompany WHERE (ID =
@@IDENTITY)
GO

tblPeople
--
ID | CompanyID | Name
--

CREATE PROCEDURE tblPeople
(
@CompanyID int,
@Name nvarchar(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO dbo.tblPeople(CompanyID, Name) VALUES (@CompanyID, @Name);
SELECT ID, CompanyID, Name FROM dbo.tblPeople WHERE (ID = @@IDENTITY)
GO

I know I'm close but I've just been looking at this too long and I'm going
cross-eyed

Any Ideas ????
 
Back
Top