473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this work?

ok, for a change I'm looking for why something "does" work.

I wanted to insert a record into an Access DB and then retrieve the
value that was just inserted. I came across this...

http://support.microsoft.com/default.aspx/kb/221931

I tried this out and it seemed to work but what I noticed is that when
it printed out the value "before" the requery it already contained the
value I was looking for. So, for some reason, this works. why and
how?

Thanks!
'
'
rsStoryData.AddNew

'rsStoryData("fld_story_catagory_ID") = Upload.Form("catagoryID")
rsStoryData("fld_story_title") = Upload.Form("title")
rsStoryData("fld_story_dateCreated") = now

rsStoryData.Update

'retrieve story ID just created and place in variable. why this works
I don't know...
storyID = rsStoryData("PK_story_ID") 'this value is the "new" just
inserted ID value
'
'

Aug 7 '06 #1
4 1385
the other john wrote:
ok, for a change I'm looking for why something "does" work.

I wanted to insert a record into an Access DB and then retrieve the
value that was just inserted. I came across this...

http://support.microsoft.com/default.aspx/kb/221931

I tried this out and it seemed to work but what I noticed is that when
it printed out the value "before" the requery it already contained the
value I was looking for. So, for some reason, this works. why and
how?

Thanks!
'
'
rsStoryData.AddNew

'rsStoryData("fld_story_catagory_ID") = Upload.Form("catagoryID")
rsStoryData("fld_story_title") = Upload.Form("title")
rsStoryData("fld_story_dateCreated") = now

rsStoryData.Update

'retrieve story ID just created and place in variable. why this works
I don't know...
storyID = rsStoryData("PK_story_ID") 'this value is the "new" just
inserted ID value
'
'
Hard to say, given that you haven't shown us your connection string or
the options used to open your recordset.

I will say that the example in the KB article
1. uses the obsolete ODBC driver
2. erroneously states that a server-side cursor cannot be used with Jet
3. because of the mistaken assumption in 2, uses a client-side cursor
which must be requeried in order to retrieve the value.

You seem to be using a server-side cursor, whose autoincr field is
automatically populated after the update method is executed.

http://www.aspfaq.com/show.asp?id=2174
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 7 '06 #2
Sorry. Here's the full version...

Set objWriteConn = Server.CreateObject("ADODB.Connection")
objWriteConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=E:\InetPub\Clients\xxxxx\cgi-bin\writing.mdb"
Set rsStoryData = Server.CreateObject("ADODB.Recordset")
storySQL = "SELECT * FROM tbl_stories;"
rsStoryData.Open storySQL, objWriteConn, adOpenStatic,
adLockOptimistic, adCmdText

rsStoryData.AddNew

'rsStoryData("fld_story_catagory_ID") = Upload.Form("catagoryID")
rsStoryData("fld_story_title") = Upload.Form("title")
rsStoryData("fld_story_dateCreated") = now
rsStoryData("fld_story_body") = Upload.Form("storyBody")
rsStoryData("fld_story_quote1") = Upload.Form("quote1")
rsStoryData("fld_story_quote2") = Upload.Form("quote2")
rsStoryData("fld_story_quote3") = Upload.Form("quote3")
rsStoryData.Update

'retrieve story ID just created and place in variable
storyID = rsStoryData("PK_story_ID")

rsStoryData.Close
Set rsStoryData = nothing
Bob Barrows [MVP] wrote:
the other john wrote:
ok, for a change I'm looking for why something "does" work.

I wanted to insert a record into an Access DB and then retrieve the
value that was just inserted. I came across this...

http://support.microsoft.com/default.aspx/kb/221931

I tried this out and it seemed to work but what I noticed is that when
it printed out the value "before" the requery it already contained the
value I was looking for. So, for some reason, this works. why and
how?

Thanks!
'
'
rsStoryData.AddNew

'rsStoryData("fld_story_catagory_ID") = Upload.Form("catagoryID")
rsStoryData("fld_story_title") = Upload.Form("title")
rsStoryData("fld_story_dateCreated") = now

rsStoryData.Update

'retrieve story ID just created and place in variable. why this works
I don't know...
storyID = rsStoryData("PK_story_ID") 'this value is the "new" just
inserted ID value
'
'
Hard to say, given that you haven't shown us your connection string or
the options used to open your recordset.

I will say that the example in the KB article
1. uses the obsolete ODBC driver
2. erroneously states that a server-side cursor cannot be used with Jet
3. because of the mistaken assumption in 2, uses a client-side cursor
which must be requeried in order to retrieve the value.

You seem to be using a server-side cursor, whose autoincr field is
automatically populated after the update method is executed.

http://www.aspfaq.com/show.asp?id=2174
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 8 '06 #3
the other john wrote:
Sorry. Here's the full version...

Set objWriteConn = Server.CreateObject("ADODB.Connection")
objWriteConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=E:\InetPub\Clients\xxxxx\cgi-bin\writing.mdb"
Set rsStoryData = Server.CreateObject("ADODB.Recordset")
storySQL = "SELECT * FROM tbl_stories;"
rsStoryData.Open storySQL, objWriteConn, adOpenStatic,
adLockOptimistic, adCmdText
You see? You are using a server-side cursor which is the default. The writer
of that KB article was wrong when he said server-side cursors could not be
used with Jet ... or he was referring to an earlier version of Jet. You are
using Jet 4.0.

<snip>
rsStoryData.Update

'retrieve story ID just created and place in variable
storyID = rsStoryData("PK_story_ID")
With server-side cursors, this field is automatically updated.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 8 '06 #4
LOL, this is so cool! All this time I've been doing work arounds for
nothing! Have to research server-side cursors.

Thanks Bob!
Bob Barrows [MVP] wrote:
the other john wrote:
Sorry. Here's the full version...

Set objWriteConn = Server.CreateObject("ADODB.Connection")
objWriteConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=E:\InetPub\Clients\xxxxx\cgi-bin\writing.mdb"
Set rsStoryData = Server.CreateObject("ADODB.Recordset")
storySQL = "SELECT * FROM tbl_stories;"
rsStoryData.Open storySQL, objWriteConn, adOpenStatic,
adLockOptimistic, adCmdText

You see? You are using a server-side cursor which is the default. The writer
of that KB article was wrong when he said server-side cursors could not be
used with Jet ... or he was referring to an earlier version of Jet. You are
using Jet 4.0.

<snip>
rsStoryData.Update

'retrieve story ID just created and place in variable
storyID = rsStoryData("PK_story_ID")

With server-side cursors, this field is automatically updated.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 8 '06 #5

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

Similar topics

7
4838
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
3
3728
by: Julian | last post by:
Hi I am trying to update a date field in my table but some how this simple code does not work, I know the select work because if I write the fields, it will show the data from the table but why...
5
3595
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
22
2570
by: Robert Bralic | last post by:
CAN anybody tell me any address where I can download some small(1000-2000) lines C++ proghram source. Or send me ,a small(1000-2000) lines C++ program source that I can compille with gpp under...
12
2916
by: Frank Hauptlorenz | last post by:
Hello Out there! I have a DB2 V7.2 Database (Fix11) on Win 2000 Professional. It was before a NT 4 based Domain - now it is a Win 2000 Domain. The database server is a domain member. Now...
0
2343
by: Jarod_24 | last post by:
How does tabindex work in ASP .net pages I dosen't seem to work quite like in regular forms. and there isn't any TabStop property either. 1 .How do you prevent a control form beign "tabbed"....
14
4815
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
5948
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
14
3450
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
1
7078
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
7129
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
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
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
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
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,...
1
5057
isladogs
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...
0
3208
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.