Hi, I have generated my queries and selected the refresh the table
option. This creates a select after the insert to get the
scope_identity() so that I can use that key value in another table,
i.e. foreign keys. I have verified the existence of the select in the
DAL .xsd file.
I simply do not know how to get that value, the scope_identity() value.
I know that it is selecting the value for me, but I have no idea how
to get that selected value after my insert. Am I supposed to get it in
my codefile somehow? Is there a way to use it in the DAL? Not sure
what the proper practice is here.
I have seen several places where stored procedures were turned to.
This does not make sense, totally, to me, but more like a workaround.
It seems that if I have an option to generate the sql to get the ID
field, then there must be a way to access the data. I don't mind
coding, but I do not want a sproc (no offense to sproc advocates. I
just want to see how to do this dynamically with Visual Studio 2005.)
Thank you for any help. 2 3970
Is the only way to use the scalar value that is returned by breaking
out of the DAL and using code behind to grab the value? ne***********@gmail.com wrote:
Hi, I have generated my queries and selected the refresh the table
option. This creates a select after the insert to get the
scope_identity() so that I can use that key value in another table,
i.e. foreign keys. I have verified the existence of the select in the
DAL .xsd file.
I simply do not know how to get that value, the scope_identity() value.
I know that it is selecting the value for me, but I have no idea how
to get that selected value after my insert. Am I supposed to get it in
my codefile somehow? Is there a way to use it in the DAL? Not sure
what the proper practice is here.
I have seen several places where stored procedures were turned to.
This does not make sense, totally, to me, but more like a workaround.
It seems that if I have an option to generate the sql to get the ID
field, then there must be a way to access the data. I don't mind
coding, but I do not want a sproc (no offense to sproc advocates. I
just want to see how to do this dynamically with Visual Studio 2005.)
Thank you for any help.
I found that I could simply enter more SQL in the DAL to accomplish
this like so:
After my initial insert in the database:
INSERT INTO table2 ([fk_employee_id]) SELECT EmployeeID FROM Employees
WHERE (EmployeeID = SCOPE_IDENTITY())
I put this in the xsd after my INSERT. To cascade deletes, I add an
additional delete to the delete command, etc. ne***********@gmail.com wrote:
Is the only way to use the scalar value that is returned by breaking
out of the DAL and using code behind to grab the value?
ne***********@gmail.com wrote:
Hi, I have generated my queries and selected the refresh the table
option. This creates a select after the insert to get the
scope_identity() so that I can use that key value in another table,
i.e. foreign keys. I have verified the existence of the select in the
DAL .xsd file.
I simply do not know how to get that value, the scope_identity() value.
I know that it is selecting the value for me, but I have no idea how
to get that selected value after my insert. Am I supposed to get it in
my codefile somehow? Is there a way to use it in the DAL? Not sure
what the proper practice is here.
I have seen several places where stored procedures were turned to.
This does not make sense, totally, to me, but more like a workaround.
It seems that if I have an option to generate the sql to get the ID
field, then there must be a way to access the data. I don't mind
coding, but I do not want a sproc (no offense to sproc advocates. I
just want to see how to do this dynamically with Visual Studio 2005.)
Thank you for any help.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scrappy |
last post by:
I have an ASP front end on SQL 2000 database. I have a form that submits to
an insert query. The entry field is an "identity" and the primary key. I
have used scope_identity() to display the...
|
by: WhiteEagl |
last post by:
Hello,
I would need some help with this identity column problem in
SQLServer.
I have a database with two tables. The Parent table has an Identity
column.
Parent (ParentID IDENTITY, Name)...
|
by: Mark |
last post by:
Hi,
I'm having a bit of difficulty in getting the identity of a new row
using the SCOPE_IDENTITY() function in SQLServer 2000.
I've added the following code: 'set @LastID = SCOPE_IDENTITY()' to...
|
by: Hardy Wang |
last post by:
Hi all,
I have the following codes, but SCOPE_IDENTITY() just returns NULL to
me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works
fine!! Since I have a trigger on the...
|
by: Ian Semmel |
last post by:
The generated INSERT statement in a typed dataset has an INSERT statement
followed by a SELECT statement which gets (I think) the value of the
autoincremented ID.
Question. How do I get hold of...
| |
by: Martin Z |
last post by:
INSERT INTO dbo.Transmission
(TransmissionDate, TransmissionDirection,
Filename, TransmittedData)
VALUES
(@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData);
SELECT @retVal =...
|
by: =?Utf-8?B?RGV2YW4=?= |
last post by:
Hi,
I have a table adapter for a database with an insert query. I want to be
able to get the PRIMARY key of the inserted record for that insert statement.
I know that SCOPE_IDENTITY is the...
|
by: Mike |
last post by:
Sql Server, Scope_Identity(), Ado.NET:
Which is better? Using an output parameter to return Scope_Identity through
ExecuteNonQuery(), or adding Select Scope_Identity() to the end of the...
|
by: Miro |
last post by:
I am trying to get my ID added from a people table in an access table
"MyContacts.mdb" i just added.
Its basically a contact file i created in access:
PK Person_ID - Unique - autoincrement...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |