K
Ken Allen
I want to be abel to permit the user to be able to view (via a DataGrid
right now), delete, edit, and add entries to a table in a database. I have
figured out nost of the issues, except...
My table has a primary key that is a sequential identifier that I do not
wish to expose to the end user at all. I retrieve the entire record from the
database table into a dataset and associate that with the DataGrid, but I
set the width of the primary key column to 0 to hide it. Cool. For delete
and edit operations I am fine. For insert operations, I want to be able to
dynamically assign the value for the primary key dynamically; the user
should not and cannot enter it. An added wrinkle is that several users may
attempt at add records to the table concurrently.
If I were doing this with direct SQL, say in a stored procedure, I would
code the statement like:
BEGIN TRANSACTION
SELECT @ID = 1 + MAX(PKey) FROM MyTable
INSERT INTO MyTable(PKey, UserValue1, UserValue2, UserValue3)
VALUES(@ID, @uVal1, !uVal2, @uVal3)
COMMIT
I would like to use the SqlDataAdapter.Update() call for a batch process,
but I cannot figure out how to craft the INSERT statement to (1) permit me
to dynamically assign the primary key field (which cannot be NULL!) or (2)
indicate in my SqlCommand that the values are to come from the dataset
itself.
Any references or answers?
-Ken
right now), delete, edit, and add entries to a table in a database. I have
figured out nost of the issues, except...
My table has a primary key that is a sequential identifier that I do not
wish to expose to the end user at all. I retrieve the entire record from the
database table into a dataset and associate that with the DataGrid, but I
set the width of the primary key column to 0 to hide it. Cool. For delete
and edit operations I am fine. For insert operations, I want to be able to
dynamically assign the value for the primary key dynamically; the user
should not and cannot enter it. An added wrinkle is that several users may
attempt at add records to the table concurrently.
If I were doing this with direct SQL, say in a stored procedure, I would
code the statement like:
BEGIN TRANSACTION
SELECT @ID = 1 + MAX(PKey) FROM MyTable
INSERT INTO MyTable(PKey, UserValue1, UserValue2, UserValue3)
VALUES(@ID, @uVal1, !uVal2, @uVal3)
COMMIT
I would like to use the SqlDataAdapter.Update() call for a batch process,
but I cannot figure out how to craft the INSERT statement to (1) permit me
to dynamically assign the primary key field (which cannot be NULL!) or (2)
indicate in my SqlCommand that the values are to come from the dataset
itself.
Any references or answers?
-Ken