Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2004, 07:40 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there guys,
Ive just come up against this problem again (and im still using access 2000 AAAARRRRRGGGHHHH!). however this time ive found this article on the MS site
http://support.microsoft.com/default...b;EN-US;221931

I think its telling me to do what sal was saying (sorry i didn't acknowledge your reply I must not have seen it) but its saying to include the adovbs.inc file (im guessing its a massive file and might be really slow. is there a more efficient way of doing that?

Also is it possible to do this using the .commandText "insert into <table> (<fields>...) values(<whatever>...)" or not?

Im still only really a beginner but i feel as though im progressing thanks to this forum (and the books :)
Cheers
Andy
 
Old April 23rd, 2004, 07:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Including the adovbs.inc file isn't that bad. However, there are two alternatives (but only one is acceptable). Check out this page:

http://www.adopenstatic.com/faq/800a0bb9step2.asp

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.


 
Old April 26th, 2004, 04:45 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok this is driving me mad now :)

I have written this page after reading the microsoft article (its basically the same. I must have done something wrong but i can't see it)
this is the kind of result im getting:

ID before Requery = 144
Absolute position =20
ID before setting absolutePosition = 99
the current records id is 98
it should be this: 144
Absolute position =20
server time of inserted record = 4/26/2004 10:32:53 AM

the code ive written is this:



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%

Dim rsID
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")

objConn.Open MM_connJobs_STRING

'move the cursor to ASP
objRS.CursorLocation = adUseClient

objRS.Open "Select * FROM tbApplicantData", objConn, adOpenStatic, adLockOptimistic

'that has got all the records from the database and we will now add a new one to it
objRS.AddNew
'there are a load of things here but ive taken them out
'for this post as they are not a problem
    objRS("fdServerTime") = CStr(now)

objRS.Update

Response.Write "<br>ID before Requery = " & objRS("ID")

rsID = objRS("ID")
response.write "<p>Absolute position =" & objRS.absolutePosition & "</p>"
bookmark = objRS.absolutePosition
objRS.Requery

Response.Write "<br>ID before setting absolutePosition = " & objRS("ID")

objRS.absolutePosition = bookmark

response.write "<p>the current records id is " & objRS("ID") & "</p>"
response.write "<p>it should be this: " & rsID & "</p>"
response.write "<p>Absolute position =" & objRS.absolutePosition & "</p>"
objRS.Filter = "ID = " & rsID

response.write "<p>server time of inserted record = " & objRS("fdServerTime") & "</p>"

objRS.Close
objConn.Close
set objConn = nothing
set objRS = nothing

%>

</body>
</html>

I dont understand why after the requery and setting the absoluteposition of the rs it is giving me the first record in the database instead of the newly inserted one, even though it is at the newly inserted record (as far as i understand it anyway).

Cheers
 
Old April 26th, 2004, 06:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well now im feeling really stupid :) my boss found an article on another website which shows you how to do it real easy. Please note this is all done using Access 2k

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
'note that this is an ADODB.Connection not a command
SET commInsert = Server.CreateObject("ADODB.Connection")
commInsert.Open MM_connJobs_STRING

varInsert = "INSERT INTO tbApplicantData(fdServerTime) VALUES('" & CStr(now) & "')"
commInsert.Execute(varInsert)

'this is the important part
SET rsNewID = commInsert.Execute("SELECT @@IDENTITY")
varNewID = rsNewID(0)

rsNewID.Close
SET rsNewID = Nothing
%>
<html>
<head>
<title>Access SELECT @@IDENTITY</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%=varNewID%>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Inserting new record with detailsview gsrai31 ASP.NET 2.0 Basics 0 November 23rd, 2008 06:29 PM
problem inserting a record with autonumber phytos VS.NET 2002/2003 2 January 16th, 2006 07:14 PM
Checking a Database before Inserting a Record vbmazza VB Databases Basics 2 April 28th, 2005 07:23 AM
Inserting A Record Set nikotromus Access VBA 3 September 14th, 2004 01:23 PM
Inserting record in Visual foxpro stella2004 SQL Language 2 September 3rd, 2004 06:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.