J
Jeronimo Bertran
Hi,
I have created a data table using SQL Server 2000 which includes an
identity field
[CollectID] [bigint] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Filename] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
I am adding new rows to a typed dataset and calling the data adapter
Update in order to Insert the new rows to the table.
My insertCommand calls a stored procedure that looks like this.
ALTER PROCEDURE spInsertCollect
(
@Filename varchar(50),
@Identity int OUTPUT
)
AS
INSERT INTO Collect(Filename) VALUES (@Filename);
SET @Identity = @@IDENTITY
RETURN
My InserCommand looks like the following:
// Create the parameters
IDataParameter[] parameters =
{
CreateDataParameter("@Filename", DbType.String, 50, "Filename"),
CreateDataParameter("@Identity", DbType.Int64, 8, "CollectID")
};
parameters[1].Direction = ParameterDirection.Output;
insertCommand = BuildStoredProcedureCommand("spInsertCollect",
parameters);
Now, before updating I set the adapter insertCommand member to the one
described above. Now, if the dataset that I pass to Update has only one
new row, then the above works fine, the new row is added to de table and
the new CollectID value is copied to the CollecID field in the dataset
for that row. However, if the dataset has multiple rows (CollectID are
numbered consecutively starting with 0 on the dataset before updating),
and I call the update method, the first row is added and the CollectID
is copied to the dataset, but the second row is not added to the
database and I get the following exception:
An unhandled exception of type 'System.Data.ConstraintException'
occurred in mydata.dll
Additional information: Column 'CollectID' is constrained to be unique.
Value '8' is already present.
Value 8 is the value that was assigned for the first row in the dataset.
Whan am I doing wrong?
Thanks
Jeronimo Bertran
I have created a data table using SQL Server 2000 which includes an
identity field
[CollectID] [bigint] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Filename] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
I am adding new rows to a typed dataset and calling the data adapter
Update in order to Insert the new rows to the table.
My insertCommand calls a stored procedure that looks like this.
ALTER PROCEDURE spInsertCollect
(
@Filename varchar(50),
@Identity int OUTPUT
)
AS
INSERT INTO Collect(Filename) VALUES (@Filename);
SET @Identity = @@IDENTITY
RETURN
My InserCommand looks like the following:
// Create the parameters
IDataParameter[] parameters =
{
CreateDataParameter("@Filename", DbType.String, 50, "Filename"),
CreateDataParameter("@Identity", DbType.Int64, 8, "CollectID")
};
parameters[1].Direction = ParameterDirection.Output;
insertCommand = BuildStoredProcedureCommand("spInsertCollect",
parameters);
Now, before updating I set the adapter insertCommand member to the one
described above. Now, if the dataset that I pass to Update has only one
new row, then the above works fine, the new row is added to de table and
the new CollectID value is copied to the CollecID field in the dataset
for that row. However, if the dataset has multiple rows (CollectID are
numbered consecutively starting with 0 on the dataset before updating),
and I call the update method, the first row is added and the CollectID
is copied to the dataset, but the second row is not added to the
database and I get the following exception:
An unhandled exception of type 'System.Data.ConstraintException'
occurred in mydata.dll
Additional information: Column 'CollectID' is constrained to be unique.
Value '8' is already present.
Value 8 is the value that was assigned for the first row in the dataset.
Whan am I doing wrong?
Thanks
Jeronimo Bertran