Obtaining Primary Key on newly established record

Results 1 to 4 of 4

Thread: Obtaining Primary Key on newly established record

  1. #1
    Join Date
    Dec 1969
    Posts
    1,912

    Default Obtaining Primary Key on newly established record

    This is what I am attempting to accomplish. The user creates a new record. This record is committed to the database using a confirmation page. I desire the confirmation page to list all the data (no problem yet) that was committed to the database plus provide the primary key (problem) of the just established record so that it can be used to add information into a related table. This appears to be fairly easy to accomplish, however I keep getting this message:<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039 80040e10&#039 <BR><BR>[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. <BR><BR>I know the parameter exists as have checked for it using the response write. It accepts my first parameter but this only returns the first record in the table. There can be duplicates in the first parameter but not the second. Here is the code (early edition)<BR><BR>&#060;!--#INCLUDE FILE ="adovbs.inc"--&#062;<BR>&#060;!--#INCLUDE FILE ="header.inc"--&#062;<BR>&#060;!--#INCLUDE FILE ="dbconn.inc"--&#062;<BR>&#060;%<BR>dim sql<BR>dim objRec<BR>dim dodid<BR>dim majcomid<BR>dim nafid<BR>dim wingid<BR>dim groupid<BR>dim squadronid<BR>dim flag<BR>dim pmocr<BR>dim tasknumber<BR>dim pmnumber<BR>dim pmname<BR>dim pmreportfreq<BR>dim pmdescription<BR>dim ocr<BR>dim pmopr<BR>dim pmassume<BR>dim rspm<BR>dim sqlpm<BR>dim wingtaskid<BR>dim i<BR><BR>userid=session("userid")<BR>dodid=session ("dodid")<BR>majcomid=session("majcomid")<BR>nafid =session("nafid")<BR>wingid=session("wingid")<BR>g roupid=session("groupid")<BR>squadronid=session("s quadronid")<BR><BR><BR>&#039get the form fields<BR>wingtaskid=request.form("tasknumber") <BR>pmnumber=request.form("pmnumber")<BR>pmname=re quest.form("pmname")<BR>pmdescription=request.form ("pmdescription")<BR>pmreportfreq=request.form("pm reportfreq")<BR>pmocr=request.form("ocr")<BR>pmass ume=request.form("pmassume")<BR><BR><BR>&#039start error checking<BR>flag=0<BR><BR>if pmnumber="" then<BR> response.write("Please enter a performance measure number, I cannot process your request without it!" & "<BR>")<BR> flag=1<BR>end if<BR><BR>if pmname="" then<BR> response.write("Please enter a short performance measure name!" & "<BR>")<BR> flag=1<BR>end if<BR><BR>if pmreportfreq="" then<BR> response.write("Please select the reporting frequency!" & "<BR>")<BR> flag=1<BR>end if<BR><BR>if pmdescription="" then<BR> response.write("Please enter a detailed description of the perfromance measure." & "<BR>")<BR> flag=1<BR>end if<BR><BR>if pmassume="" then<BR> response.write("Please enter your assumptions, to aid in deteriming the fluctuation of datapoints!" & "<BR>")<BR> flag=1<BR>end if<BR> <BR>If flag &#060;&#062; 1 then<BR><BR><BR>Set objRec=Server.CreateObject("ADODB.RecordSet")<BR>s ql="SELECT * FROM tblpm"<BR>objRec.Open sql,Conn,3,3<BR><BR>objRec.AddNew<BR>objRec.Fields ("pmname")=pmname<BR>objRec.Fields("pmnumber")=pmn umber<BR>objRec.Fields("pmdescription")=pmdescript ion<BR>objRec.Fields("pmopr")=squadronid<BR>objRec .Fields("pmocr")=pmocr<BR>objRec.Fields("pmreportf req")=pmreportfreq<BR>objRec.Fields("pmassume")=pm assume<BR>objRec.Fields("wingtaskid")=wingtaskid<B R>objRec.Fields("userid")=userid<BR>objRec.Fields( "dodid")=dodid<BR>objRec.Fields("nafid")=nafid<BR> objRec.Fields("majcomid")=majcomid<BR>objRec.Field s("wingid")=wingid<BR>objRec.Fields("groupid")=gro upid<BR>objRec.Fields("squadronid")=squadronid<BR> objRec.Update<BR>objRec.close &#039testing remove later place at end<BR>set objRec=nothing &#039testing remove later place at end<BR>%&#062;<BR>&#060;html&#062;<BR><BR>&#060;he ad&#062;<BR>&#060;title&#062;Process New PM&#060;/title&#062;<BR>&#060;/head&#062;<BR><BR>&#060;body background="images/sideback.gif"&#062;<BR><BR>&#060;table border="0" width="985" bordercolor="#FFFFFF" bordercolorlight="#FFFFFF"<BR>bordercolordark="#FF FFFF" cellspacing="1" cellpadding="0"&#062;<BR> &#060;tr&#062;<BR> &#060;td width="83"&#062;&#060;/td&#062;<BR> &#060;td width="786"&#062;&#060;h2 align="center"&#062;Mission Essential Task Addition Results&#060;/h2&#062;<BR> &#060;/td&#062;<BR> &#060;td width="94"&#062;&#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;tr&#062;<BR> &#060;td width="83"&#062;&#060;!--#INCLUDE FILE ="sidenav.htm"--&#062; &#060;/td&#062;<BR> &#060;td width="786"&#062;The addition was successful! The following was added to the database:&#060;p&#062;Performance<BR> Measure Number:&#060;%=pmnumber%&#062;&#060;/p&#062;<BR> &#060;p&#062;Performance Measure Name:&#060;%=pmname%&#062;&#060;/p&#062;<BR> &#060;p&#062;Performance Measure Reporting Frequency:&#060;%=pmreportfreq%&#062;&#060;/p&#062;<BR> &#060;p&#062;Performance Measure Description:&#060;%=pmdescription%&#062;&#060;/p&#062;<BR> &#060;p&#062;Performance Measure OCR:&#060;%=pmocr%&#062;&#060;/p&#062;<BR> &#060;p&#062;Performance Measure Assumptions:&#060;%=pmassume%&#062; &#060;/td&#062;<BR>&#060;%<BR>response.write pmnumber &#039check to see if exists remove later<BR>response.write wingtaskid &#039check to see if exists remove later<BR>set rspm=server.createObject("ADODB.RecordSet")<BR>sql pm="SELECT pmid,pmnumber,wingtaskid FROM tblpm WHERE wingtaskid=" & wingtaskid &"" &_<BR>"AND pmnumber=" & pmnumber &""<BR>rspm.open sqlpm,Conn,3,3 <BR>%&#062;<BR>&#060;%else%&#062;<BR> &#060;td width="94"&#062;The update was NOT successful &#060;%end if%&#062;

  2. #2
    Damien O'Hara Guest

    Default RE: Obtaining Primary Key on newly established rec

    Select @MynewRecordID = @@identity<BR><BR>@@IDENTITY*<BR>Saves the last-inserted IDENTITY value. The @@IDENTITY variable is updated specifically for each user when an INSERT or SELECT INTO statement or bulk copy inserting into a table occurs. If a statement changes the table without an identity column, @@IDENTITY is set to NULL. The @@IDENTITY value does not revert to a previous setting if the INSERT or SELECT INTO statement or bulk <BR><BR><BR><BR>Hope this helps<BR><BR><BR>Damien

  3. #3
    Vivek Nama Guest

    Default Obtaining Primary Key on newly established rec

    just check knowledge base articles <BR>http://support.microsoft.com/support/kb/articles<BR>for problems in @@identity which have been sorted out in sql server service pack 1 <BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    1,912

    Default RE: Obtaining Primary Key on newly established rec

    Thanks for the assistance.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •