I hope someone will be able to help me with the problem I am having.
When the trigger i have attached to my main table is fired it is entering the policyID from the main table into the sub table but it is entering the information entered through the form into a separate row in the sub table instead of the same row as the primary key was entered into.
Any help with this would greatly be appreciated.
Below is my trigger and asp code.
Trigger
CREATE TRIGGER PolicyID ON [dbo].[tbl_policy_main_donna]
FOR INSERT, UPDATE, DELETE
AS
if @@rowcount = 0
return
Insert into tbl_policies_sub_donna (PolicyID)
select PolicyID 'int' from inserted
ASP Code
<!-- #INCLUDE file="../incs/header.inc" -->
<!-- #INCLUDE file="../incs/dbconn_policies.inc" -->
<html>
<head>
<SCRIPT LANGUAGE="Javascript">
function ValidateTextboxes() {
if (document.addPolicy.policyref.value.length < 1 || document.addPolicy.fileref.value.length < 1 || document.addPolicy.linkeddoc.value.length < 1 || document.addPolicy.source.value.length < 1 || document.addPolicy.leadperson.value.length < 1 || document.addPolicy.writtendate.value.length < 1 || document.addPolicy.revieweddate.value.length < 1){
alert("You must fill in all the fields.");
return false;
}
else{
return true;}
}
</SCRIPT></head>
<body>
<%
Dim Conn
'Create an ADO connection and recordset object
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs= Server.CreateObject("ADODB.Recordset")
'Set an active connection and select fields from the database
Conn.Open "Driver={SQL Server};Server=nbhq-sql01;Database=policies;Uid=scott;Pwd=password;"
strQuery = "SELECT * FROM tbl_policy_main_donna;"
strQuery2 = "SELECT * FROM tbl_policies_sub_donna;"
Set rstPolicy = Conn.Execute(strQuery)
Set rstPolicy2 = Conn.Execute(strQuery2)
Dim policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate
policyRef = Request.Form("policyref")
fileRef = Request.Form("fileref")
linkedDoc = Request.Form("linkeddoc")
policySource = Request.Form("source")
leadPerson = Request.Form("leadperson")
writtenDate = Request.Form("writtendate")
reviewedDate = Request.Form("revieweddate")
Sub insertData(policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate)
If ((policyRef = "") or (fileRef = "") or (linkedDoc = "")) Then
Else
Set rstInsertPolicyMain = Conn.Execute("INSERT INTO tbl_policy_main_donna(Policy_Ref, File_Reference, linked_document) VALUES('" & policyRef & "','" & fileRef & "','" & linkedDoc & "' );")
'rstPolicy1.Close
'rstPolicy1 = nothing
Set rstInsertPolicySub = Conn.Execute("INSERT INTO tbl_policies_sub_donna(Source, Lead_Person, Date_Written, Date_Revised) VALUES('" & policySource & "','" & leadPerson & "','" & written & "','" & reviewed & "' );")
'rstPolicy1.Close
End If
End Sub
%>
<form name="addPolicy" method="post" action="<% call insertData(policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate) %>" onSubmit="return ValidateTextboxes();">
<table width="75%" border="0" align="center" bordercolor="#000066">
<tr>
<td bgcolor="#FFFFFF">
<div align="center">
<p><strong>Enter the new Policy below and Click on Submit</strong></p>
<table width="37%" border="1" bordercolor="#000066">
<tr>
<td width="52%" bgcolor="#99CCFF"><font color="#FFFFFF">Policy Ref</font></td>
<td width="48%"><input type="text" name="policyref" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Source</font></td>
<td><input type="text" name="source" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Lead Person</font></td>
<td><input type="text" name="leadperson" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Written</font></td>
<td><input type="text" name="writtendate" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Reviewed</font></td>
<td><input type="text" name="revieweddate" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">File Reference</font></td>
<td><input type="text" name="fileref" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Linked Document</font></td>
<td width="48%"><input type="text" name="linkeddoc" maxlength="45"></td>
</tr>
</table>
<p>
<input type="submit" name="Save" value="Submit">
</p>
</div>
<div align="center">
<p><a href="javascript:self.close()">Close this window</a> </p>
</div></td>
</tr>
</table>
</form>
</body>
</html>
<!-- #INCLUDE file="../incs/footer.inc" -->
When the trigger i have attached to my main table is fired it is entering the policyID from the main table into the sub table but it is entering the information entered through the form into a separate row in the sub table instead of the same row as the primary key was entered into.
Any help with this would greatly be appreciated.
Below is my trigger and asp code.
Trigger
CREATE TRIGGER PolicyID ON [dbo].[tbl_policy_main_donna]
FOR INSERT, UPDATE, DELETE
AS
if @@rowcount = 0
return
Insert into tbl_policies_sub_donna (PolicyID)
select PolicyID 'int' from inserted
ASP Code
<!-- #INCLUDE file="../incs/header.inc" -->
<!-- #INCLUDE file="../incs/dbconn_policies.inc" -->
<html>
<head>
<SCRIPT LANGUAGE="Javascript">
function ValidateTextboxes() {
if (document.addPolicy.policyref.value.length < 1 || document.addPolicy.fileref.value.length < 1 || document.addPolicy.linkeddoc.value.length < 1 || document.addPolicy.source.value.length < 1 || document.addPolicy.leadperson.value.length < 1 || document.addPolicy.writtendate.value.length < 1 || document.addPolicy.revieweddate.value.length < 1){
alert("You must fill in all the fields.");
return false;
}
else{
return true;}
}
</SCRIPT></head>
<body>
<%
Dim Conn
'Create an ADO connection and recordset object
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs= Server.CreateObject("ADODB.Recordset")
'Set an active connection and select fields from the database
Conn.Open "Driver={SQL Server};Server=nbhq-sql01;Database=policies;Uid=scott;Pwd=password;"
strQuery = "SELECT * FROM tbl_policy_main_donna;"
strQuery2 = "SELECT * FROM tbl_policies_sub_donna;"
Set rstPolicy = Conn.Execute(strQuery)
Set rstPolicy2 = Conn.Execute(strQuery2)
Dim policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate
policyRef = Request.Form("policyref")
fileRef = Request.Form("fileref")
linkedDoc = Request.Form("linkeddoc")
policySource = Request.Form("source")
leadPerson = Request.Form("leadperson")
writtenDate = Request.Form("writtendate")
reviewedDate = Request.Form("revieweddate")
Sub insertData(policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate)
If ((policyRef = "") or (fileRef = "") or (linkedDoc = "")) Then
Else
Set rstInsertPolicyMain = Conn.Execute("INSERT INTO tbl_policy_main_donna(Policy_Ref, File_Reference, linked_document) VALUES('" & policyRef & "','" & fileRef & "','" & linkedDoc & "' );")
'rstPolicy1.Close
'rstPolicy1 = nothing
Set rstInsertPolicySub = Conn.Execute("INSERT INTO tbl_policies_sub_donna(Source, Lead_Person, Date_Written, Date_Revised) VALUES('" & policySource & "','" & leadPerson & "','" & written & "','" & reviewed & "' );")
'rstPolicy1.Close
End If
End Sub
%>
<form name="addPolicy" method="post" action="<% call insertData(policyRef, fileRef, linkedDoc, policySource, leadPerson, writtenDate, reviewedDate) %>" onSubmit="return ValidateTextboxes();">
<table width="75%" border="0" align="center" bordercolor="#000066">
<tr>
<td bgcolor="#FFFFFF">
<div align="center">
<p><strong>Enter the new Policy below and Click on Submit</strong></p>
<table width="37%" border="1" bordercolor="#000066">
<tr>
<td width="52%" bgcolor="#99CCFF"><font color="#FFFFFF">Policy Ref</font></td>
<td width="48%"><input type="text" name="policyref" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Source</font></td>
<td><input type="text" name="source" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Lead Person</font></td>
<td><input type="text" name="leadperson" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Written</font></td>
<td><input type="text" name="writtendate" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Reviewed</font></td>
<td><input type="text" name="revieweddate" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">File Reference</font></td>
<td><input type="text" name="fileref" maxlength="45"></td>
</tr>
<tr>
<td bgcolor="#99CCFF"><font color="#FFFFFF">Linked Document</font></td>
<td width="48%"><input type="text" name="linkeddoc" maxlength="45"></td>
</tr>
</table>
<p>
<input type="submit" name="Save" value="Submit">
</p>
</div>
<div align="center">
<p><a href="javascript:self.close()">Close this window</a> </p>
</div></td>
</tr>
</table>
</form>
</body>
</html>
<!-- #INCLUDE file="../incs/footer.inc" -->