This topic is locked

Insert a record

11/10/2005 5:41:37 AM
ASPRunnerPro General questions
H
heje author

Assume I have two tables which are not in a master-detail relationship

TableA with the following fields: A(primary key), B, C, D, E and F

TableB with the following fields: A(primary key), E, and F (same fields as mentioned above)
When the user presses the SAVE button in _edit.asp for TableA, I need a record to be inserted in TableB with the values from TableA.
To that end I have added variants of the following code in _edit.asp:
if (GetRequestForm("saveid")<>"" and GetRequestForm("action")="edit") then

strSQL = "insert into TableB (A, E, F) values ('"& Request.Form("saveid") &"', '"& Request.Form("E") &"','"& Request.Form("F") &"')"

dbConnection.Execute strSQL

end if
However, when I press the SAVE button I either get muliple entries in TableB or none or assorted errors.
Therefore, What should I do?
Thanks in advance

Torben

Sergey Kornilov admin 11/10/2005

Torben,
please use GetRequestFormfunction instead of Request.Form.
As for the rest your code looks correct for me.

H
heje author 11/10/2005

Per your suggestion changed to the GetRequestForm.
However, if I embed the strSQL statement in the below mentioned if-then-else statement the program run fine, but do not insert any record.
If I comment-out the if-then-else, I get the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/xxx/yyy/01CallSalesLead_edit.asp, line 2382
Below please find the actual code added to the _edit.asp right above the generated

'end if

if strADOXTableName<>"" then set oCat=Nothing

line:
2374 if (GetRequestForm("saveid")<>"" and GetRequestForm("action")="edit") then

2375

2376 'some session variables placed in another program

2377 Session("CallDateVar") = NOW()

2378 Session("CallEndVar") = NOW()

2379

2380 'the insert

2381 strSQL = "insert into SalesLead2History (SalesLeadID, CallDate, CallOutcomeID, Remarks, EmployeeID, CallEnd) values ('"& GetRequestForm("saveid") &"', '" & Session("CallDateVar") & "','"& GetRequestForm("CallOutcomeID") &"','"& GetRequestForm("Remarks") &"','" & Session("UserID") & "', '" & Session("CallEndVar") & "' )"

2382 dbConnection.Execute strSQL

2383

2384 end if
Your suggestion(s) are very much velcomed.
Thanks in advance.
Torben

Sergey Kornilov admin 11/10/2005

Torben,
insert the following after line 2381 :

response.write strSQL

response.end


Then run the pages, copy SQL string and execute it directly on your database to find what's wrong.

H
heje author 11/10/2005

Hi Sergey
Your help is really above and beyond, and I appreciate is very much.
Running the _edit.asp with the if-then and end-if lines commented out and with the added code per your above suggestion, produced the following result:

insert into SalesLead2History

(SalesLeadID, CallDate, CallOutcomeID, Remarks, EmployeeID, CallEnd)

values

('', '10-11-2005 23:03:48','','','the_correct_UserID_is_inserted_here', '10-11-2005 23:03:48' )
The session variables are inserted correctly, but it apparently does not insert the value of

  1. the first field SalesLeadID (which is the primary key) using GetRequestForm("saveid").
  2. the third and fourth field using GetRequestForm("CallOutcomeID") and GetRequestForm("Remarks") respectively
    Please note that Edit is not allowed for the first field while the user can edit all the other fields and save, i.e. update, the record.
    At this point, what do you suggest as the best course of action.
    All the best

    Torben

Sergey Kornilov admin 11/11/2005

Torben,
the current ASPRunner version uses editid and todo form parameters instead of saveidand action.
So please upgrade your ASPRunnerPro if you use pre-3.2 and modify your code to fit the last version.

H
heje author 11/11/2005

Hi Sergey,
It works with your suggested parms. Those I used were based on an earliere posting from another user w/o being aware of the change.
However, the value regarding CallOutcomeID (Datatype:Text, Size:1 and labeled on the page as LastCall) is not inserted, properly for this reason:
In ASPrunner v3.2 this field is defined in Step 8 under "Edit as" as a Lookup wizard and under "Edit format" as:

Required field - Yes

Lookuptable - Yes

Table - xCallOutcome

Linkfield - CallOutcomeID (the key)

Displayfield - CallOutcome (the description)

Order by - CallOutcomeID
A final question, can you suggest how and where I can "catch" the CallOutcomeID value and transfer it to the SalesLead2History table's field with the same name.
All the best

Torben

Sergey Kornilov admin 11/11/2005

Torben,
it's quite difficult to find out remotelly why the modified code doesn't work.
You can send to support@xlinesoft.com your generated ASP files along with your database with sample data and I'll help you to get them work.

H
heje author 11/13/2005

Hi Sergey
Thank you, but I managed later that evening to figure out where to "catch" the value by adding the code shown in blue below below:

  sFieldName = "CallOutComeID"

 

  if rs.EOF and rs.BOF then

  strValue=""

  else

  strValue = GetData(rs.Fields(sFieldName), FORMAT_NONE )

  Session("CallOutComeIDvar") = strvalue '<--- Added

  end if
  if GetEditFormat(sFieldName) <> EDIT_FORMAT_HIDDEN then

      Response.Write vbCRLF & "<tr><td class=shade>"

  Response.Write Label(sFieldName) & " "

      Response.Write "</td><td>"

  end if


All the best

Torben