muhd fauzi
|
| Posted: 07/23/2004, 9:47 AM |
|
I have the following code at after execute insert :
dim phylinkid
dim ncount
phylinkid = CInt(CCDlookUp("phylinkid", "pyphylink", "stationa=" & DBMyNipsDc.Tosql( CCGetParam("stationa",Empty ), CcsText ) & " and stationb=" & DBMyNipsDc.Tosql( CCGetParam("stationb",Empty ), CcsText ) & " and `type`=" & DBMyNipsDc.Tosql( CCGetParam("linktype",Empty ), CcsText ) & " and plucount=" & DBMyNipsDc.Tosql( CCGetParam("plucount",Empty ), CcsInteger ) & " and `phylinkno`=" & DBMyNipsDc.Tosql( CCGetParam("phylinkno",Empty ), CcsText ) & "", DBMyNipsDc ))
ncount = 1
while ncount <= pyphylink1.plucount.value
SQL = "INSERT INTO pyplu (phylinkid, pluno ) VALUES (" & DBMyNipsDc.tosql( phylinkid, ccsInteger ) &","& DBMyNipsDc.tosql( ncount , ccsInteger) &")"
'response.write "sql:" & sql & "<br>"
'DBMyNipsDc.Execute(SQL)
ncount = ncount + 1
wend
It seems that the statement ' sql = ' is giving the error, but I cannot find it . Tried all sort of thing but stll not work.
|
|
|
 |
dataobjx
Posts: 181
|
| Posted: 07/23/2004, 5:25 PM |
|
Try This
Dim lngPhyLinkID
Dim lngNCount
lngPhyLinkID = DBMyNipsDc.tosql( phylinkid, ccsInteger )
lngNCount = DBMyNipsDc.tosql( ncount , ccsInteger)
SQL = "INSERT INTO pyplu (phylinkid, pluno ) VALUES (" & lngPhyLinkID &","& lngNCount &")"
If Not InsertPyPLU(SQL) Then
Response.write "InsertPyPLU() Failed<br>" & SQL
Response.end
End If
Add this function to your events page;
Function InsertPyPLU(vSQL)
Dim Connection
Dim ErrorMessage
InsertPyPLU = False 'default/assume failure
Set Connection = New clsDBMyNipsDc
Connection.Open
Connection.Execute(vSQL)
If Connection.Errors.Count = 0 Then InsertPyPLU = True
Connection.Close
Set Connection = Nothing
On Error Goto 0
End Function
This should work for you. If it doesn't you'll need to provide more information.
_________________
www.DataObjx.net
www.mydigitalapps.com |
 |
 |
muhd fauzi
|
| Posted: 07/23/2004, 6:15 PM |
|
I've tried with the following code but it fails :
Function pyphylink1_DataSource_AfterExecuteInsert() 'pyphylink1_DataSource_AfterExecuteInsert @62-EEE131D1
'Custom Code @133-73254650
' -------------------------
' Write your own code here.
' -------------------------
dim nphylinkid
dim ncount
dim phylinkplu
dim countplu
nphylinkid = CInt(CCDlookUp("phylinkid", "pyphylink", "stationa=" & DBMyNipsDc.Tosql( CCGetParam("stationa",Empty ), CcsText ) & " and stationb=" & DBMyNipsDc.Tosql( CCGetParam("stationb",Empty ), CcsText ) & " and `type`=" & DBMyNipsDc.Tosql( CCGetParam("linktype",Empty ), CcsText ) & " and plucount=" & DBMyNipsDc.Tosql( CCGetParam("plucount",Empty ), CcsInteger ) & " and `phylinkno`=" & DBMyNipsDc.Tosql( CCGetParam("phylinkno",Empty ), CcsText ) & "", DBMyNipsDc ))
ncount = 1
while ncount <= pyphylink1.plucount.value
phylinkplu = DBMyNipsDc.tosql( nphylinkid , ccsinteger )
countplu = DBMyNipsDc.tosql( ncount , ccsinteger )
SQL = "INSERT INTO pyplu (phylinkid, pluno ) VALUES (" & phylinkplu & ","& countplu & ")" ' ####fails here ###
'response.write "sql:" & sql & "<br>"
'DBMyNipsDc.Execute(SQL)
'response.write "after insert:" & ncount & "<br>"
ncount = ncount + 1
wend
note:
the events requires to retrieve new parentkey value phylinkid from table pyphylink after it is created. In the code the value is stored in nphylinkid. = ccdlookup(...
The new phylinkid is used to create child records with not more than pyphylink1.plucount.value .The sql = is the required sql to create each child record. Ncount is used as counter and could not exceed plucount.
I hope that will clear thing up.
|
|
|
 |
dataobjx
Posts: 181
|
| Posted: 07/23/2004, 9:09 PM |
|
If Your using SQL Server you can get the identity (pk) with the following code.
nphylinkid = CCDLookUp("@@IDENTITY", "pyphylink", "phylinkid=@@IDENTITY", DBMyNipsDc)
If you're not using sql server, tell us what database you are using.
_________________
www.DataObjx.net
www.mydigitalapps.com |
 |
 |
muhd fauzi
|
| Posted: 07/24/2004, 4:55 AM |
|
I'm using mysql 4.0 / w2003/iis/asp
|
|
|
 |
muhd fauzi
|
| Posted: 07/24/2004, 5:00 AM |
|
I've tested every single line of code in the after execute insert event. The form crash when sql = "insert.. " is not comment out. When it is comment out, the code works .
|
|
|
 |
|