473,395 Members | 1,941 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,395 software developers and data experts.

SQL query question

347 100+
I am inserting a record into an access database but at the same time i want to know what the personal id number of the new record is at the same time? Is this possible??
Jul 16 '09 #1
5 1746
colinod
347 100+
i have found ou how to do this but i am having a problem retrieving the information.

I am sending the id of the information written to the database in a link via email with the following

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Response.Expires=0
  3. Set mailConnection=Server.CreateObject("ADODB.Connection")
  4. DatabaseDetails="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../../private/database.mdb") & ";"
  5. mailConnection.Open DatabaseDetails
  6. mailQuery="INSERT INTO mailouttext (mailtext) VALUES ('"&textnew&"')"
  7. set rs = mailConnection.execute("select MAX(ID) from mailouttext") 
  8. Set mailRecordset=mailConnection.execute(mailQuery)
  9. %>
  10. <%
  11.  
  12. 'Sends an email
  13.  
  14. Dim usrmail
  15. Dim usrcart
  16. Dim usrtext
  17. usrcart = Request.Form("link") & "&id=" & rs(0)
  18. Response.Write(usrcart)
  19. Set usrmail=Server.CreateObject("CDO.Message")
  20. usrmail.To=Request.Form("To")
  21. usrmail.From="voiceovers@yaketyyak.co.uk"
  22. usrmail.Bcc=Request.Form("Bcc1")
  23. usrmail.Subject=Request.Form("Subject")
  24. usrmail.CreateMHTMLBody "http://www.website.co.uk/mailout/viewshortlist3.asp" & usrcart
  25. usrmail.Send()
  26. Response.Write("")
  27. 'Destroy the mail object!
  28. Set usrmail = nothing
  29. %>
the problem is that when the email is recieved the page it displays has the information that was typed in for the previous email??
Jul 16 '09 #2
GazMathias
228 Expert 128KB
Hi,

I know you've written a lot already, but you might want to look into the ADO Record Set object's AddNew method.

Expand|Select|Wrap|Line Numbers
  1. rs.AddNew ' Add a new row to the recordset (not the table)
  2. rs("SomeField") = "SomeValue" ' Insert some data
  3. ' Add more fields
  4. rs.Update  'Save your changes
  5. rs.MoveLast 'Go to the record you just created
  6.  
  7. Response.Write rs("ID")  'This should let you grab the ID (assuming it is auto incremented by the DB)
  8.  
Gaz
Jul 17 '09 #3
colinod
347 100+
sorry Gaz i can see how to get this into my code at the moment??? not that good with ASP but am learning all the time i have tried the following

Expand|Select|Wrap|Line Numbers
  1. <%'Read in the value of the TEXTAREA
  2. Dim textnew 
  3. textnew = Request.Form("body2") 
  4. 'Replace all vbCrLf with <BR>s 
  5.  
  6. textnew = Replace(textnew, vbCrLf, "<BR>") 
  7.  
  8. 'Replace all spaces with &nbsp; 
  9.  
  10. textnew = Replace(textnew, " ", "&nbsp;") 
  11. %>
  12.  
  13. <%
  14. Response.Expires=0
  15. Set mailConnection=Server.CreateObject("ADODB.Connection")
  16. DatabaseDetails="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../../private/mailouts.mdb") & ";"
  17. mailConnection.Open DatabaseDetails
  18. mailQuery="SELECT * from mailouttext"
  19. Set mailRecordset=mailConnection.execute(mailQuery)
  20. mailRecordset.AddNew ' Add a new row to the recordset (not the table) 
  21. mailRecordset("mailtext") = "textnew" ' Insert some data 
  22. ' Add more fields 
  23. mailRecordset.Update  'Save your changes 
  24. mailRecordset.MoveLast 'Go to the record you just created 
  25.  
  26. Response.Write mailRecordset("ID")  'This should let you grab the ID (assuming it is auto incremented by the DB) 
  27.  
  28. %>
but it comes back with the following

ADODB.Recordset error '800a0cb3'

Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.

/mailout/mailoutemail.asp, line 20

line 20 is the addnew line
Jul 17 '09 #4
GazMathias
228 Expert 128KB
Hi,

You need to provide a LockType, either optimistic (lock only when updating) or pessimistic (record by record).

The general form for this type of operation is explained pretty well here http://www.w3schools.com/ADO/prop_rs_locktype.asp, but there are loads of other examples out there. A simple "rs.update" search on Google yields plenty.

Gaz
Jul 17 '09 #5
colinod
347 100+
thanks for your help, i have actually changed the way im going to do this and just encoded the url and the replaced the characters on the page that views the text
Jul 17 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
3
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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
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.