473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

DB insert question

Ok i know that using an access db is a corporate nono but i am not about to
buy sql for anybody (well maybe myself someday) and an approved msde update
must come AFTER i get certain things up and going. With that in mind, i have
a problem and i was wondering if anyone could maybe confirm my hunch.

I have an asp.net app that inserts a form into a db. The user inserts the
info then a parametized query runs updates the db. After the code runs the
db update code it grabs the current identity from the database then
redirects to a display page that allows the user to see the newly inserted
data.

Sometimes, the redirect page displays data not for the record that was just
inserted but rather the one inserted before that. So if i were using
autoincrement for my pk and had just inserted record number 15, the details
page will show record 14 instead. I suspect what is happening is that
somehow the page is getting the @@identity back before the record was
inserted. Is this possible? if so are there work arounds?

thanks steve
Nov 18 '05 #1
3 1289
I haven't experienced that problem myself, but I think it is possible. Have you tried to wrap the insert in a transaction

Tu-Thac

----- A Lonely Programmer wrote: ----

Ok i know that using an access db is a corporate nono but i am not about t
buy sql for anybody (well maybe myself someday) and an approved msde updat
must come AFTER i get certain things up and going. With that in mind, i hav
a problem and i was wondering if anyone could maybe confirm my hunch

I have an asp.net app that inserts a form into a db. The user inserts th
info then a parametized query runs updates the db. After the code runs th
db update code it grabs the current identity from the database the
redirects to a display page that allows the user to see the newly inserte
data

Sometimes, the redirect page displays data not for the record that was jus
inserted but rather the one inserted before that. So if i were usin
autoincrement for my pk and had just inserted record number 15, the detail
page will show record 14 instead. I suspect what is happening is tha
somehow the page is getting the @@identity back before the record wa
inserted. Is this possible? if so are there work arounds

thanks stev

Nov 18 '05 #2
I haven't. i was under the impression that transactions and access are like
radios and a bathtub. I'll look into this tomorrow morning, thanks a ton

steve

"Tu-Thach" <tu*****@antispam.ongtech.com> wrote in message
news:86**********************************@microsof t.com...
I haven't experienced that problem myself, but I think it is possible. Have you tried to wrap the insert in a transaction?
Tu-Thach

----- A Lonely Programmer wrote: -----

Ok i know that using an access db is a corporate nono but i am not about to buy sql for anybody (well maybe myself someday) and an approved msde update must come AFTER i get certain things up and going. With that in mind, i have a problem and i was wondering if anyone could maybe confirm my hunch.

I have an asp.net app that inserts a form into a db. The user inserts the info then a parametized query runs updates the db. After the code runs the db update code it grabs the current identity from the database then
redirects to a display page that allows the user to see the newly inserted data.

Sometimes, the redirect page displays data not for the record that was just inserted but rather the one inserted before that. So if i were using
autoincrement for my pk and had just inserted record number 15, the details page will show record 14 instead. I suspect what is happening is that
somehow the page is getting the @@identity back before the record was
inserted. Is this possible? if so are there work arounds?

thanks steve

Nov 18 '05 #3

I assume that you are talking to a sql server... do the following:

-- begin sql script

set nocount on

insert into -- yadda yadda yadda... do your insert here

select scope_identity() as theRowID

-- end sql script...

then in your asp.net code, execute the statement, and get the dataset/sqldatareader and get the value of "theRowID" column.

Don't use @@identity. Always use scope_identity(). See the TSql for more info. @@identity is subject to alteration by triggers, etc. Basically, when you want to find out the row id after an insert, always use scope_identity().

Good Luck!



----- A Lonely Programmer wrote: -----

Ok i know that using an access db is a corporate nono but i am not about to
buy sql for anybody (well maybe myself someday) and an approved msde update
must come AFTER i get certain things up and going. With that in mind, i have
a problem and i was wondering if anyone could maybe confirm my hunch.

I have an asp.net app that inserts a form into a db. The user inserts the
info then a parametized query runs updates the db. After the code runs the
db update code it grabs the current identity from the database then
redirects to a display page that allows the user to see the newly inserted
data.

Sometimes, the redirect page displays data not for the record that was just
inserted but rather the one inserted before that. So if i were using
autoincrement for my pk and had just inserted record number 15, the details
page will show record 14 instead. I suspect what is happening is that
somehow the page is getting the @@identity back before the record was
inserted. Is this possible? if so are there work arounds?

thanks steve

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Bedford | last post by:
I've a textarea and would like to save the content in a mysql table each time a user click on a form. How can I do for avoiding error when the user put a " or a ' in the message, or any other...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
4
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
5
by: TThai | last post by:
HI, I'm trying to insert records to a table using bcp command. The problem is the input file to the bcp is a text file that looks like this: Text file data: 1234 abc def ghi jkl mno ...
11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
25
by: Andreas Fromm | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
10
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
24
by: Henry J. | last post by:
My app needs to insert thousand value rows into a mostly empty table (data are read from a file). I can either use inserts, or use merge. The advantage of using merge is that in the few cases...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.