Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DB insert question

Reply
Thread Tools

DB insert question

 
 
A Lonely Programmer
Guest
Posts: n/a
 
      02-17-2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VHUtVGhhY2g=?=
Guest
Posts: n/a
 
      02-17-2004
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



 
Reply With Quote
 
 
 
 
Muckey
Guest
Posts: n/a
 
      02-18-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
=?Utf-8?B?U3RldmUgTWVudHplcg==?=
Guest
Posts: n/a
 
      02-18-2004

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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Multiple Records Using One Insert Statemen with MySQLdb module anton.ranieri.it@gmail.com Python 1 12-06-2008 12:47 PM
insert in std::map does not insert the object simon.elbaz@free.fr C++ 1 11-04-2007 11:42 PM
Insert & Insert/Repeat buttons in a detailsview eagle ASP .Net Datagrid Control 0 07-12-2007 12:47 PM
Detailsview loses insert mode contents when Insert fails... cannontrodder ASP .Net 1 07-25-2006 08:38 AM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM



Advertisments