Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Validate exclusion of duplicate data - Please help!!


Message #1 by "Melinda Savoy" <msavoy@h...> on Tue, 29 Jan 2002 13:22:07
ok,
whenever you make an update to a database it return error code and a message
in Err.description.
What I do I check error message for SQLSTATE= combination.
In my database 23505 code means duplicate key error so I am showing
appropriate message.

You can check oConn.Errors collection for errors as well it depends on you
application.

Or create some array like :

var Values = new Array;
Values[1] = 'somethin1';
Values[2] = 'somethin2';
Values[3] = 'somethin3';
Values[4] = 'somethin4';
Values[5] = 'somethin5';

and then check this array for new value that you want to add if it exists in
this array.
But you should do it only for small tables that not changes so often...

Oleg


-----Original Message-----
From: Melinda Savoy [mailto:msavoy@h...]
Sent: January 29, 2002 4:03 PM
To: javascript
Subject: [javascript] RE: Validate exclusion of duplicate data - Please
help!!


Oleg,

Thanks for the info.  But how do I do what you're suggesting?  I've tried
a few things on my side but to no avail.  Your additional help would be
appreciated.

Thanks.


> Hi !
>
> I have almost the same functionality so what I do I INSERT data
> in any case and if this key already exists database returns me
> an SQLCODE.
> Then I am checking this SQL code and present an error message.
> If your table is small you can do something else.
> You can put all table values into JavaScript array
> and then check against this array instead of going to Database every
time.
>
> Oleg.
>
> -----Original Message-----
> From: Melinda Savoy [mailto:msavoy@h...]
> Sent: January 29, 2002 8:22 AM
> To: javascript
> Subject: [javascript] Validate exclusion of duplicate data - Please
> help!!
>
>
> Question:  I have a form whereby I have 3 submit buttons on one form.
I
> have a REMOVE button, ADD button and SUBMIT button.  My problem is when
I
> click on the ADD button to add a record from a drop-down box to a
> displayed table within the form I want to ensure that a record is not
> already displayed in this table.  Here is my code, and I realize it is
> lengthy, on how I am displaying the records in the table and in my
HTML,
> any HELP or direction would be appreciated  THANKS:
>
> VBScript code:
>
> '***** Select statement to build physician's procedures table. *****
> strSQLProfileProcdr =	"SELECT DISTINCT enterprsphysnid, procdrcode,
> tableresult " & _
> "FROM OPENQUERY(LOOKUPTABLES,'SELECT * FROM GetLookUpTableValues_Fun
> (''PhysnProfileProcdr'',''a'')') " & _
> "LEFT OUTER JOIN THRPhysnProcdr_view " & _
> "ON tableargmnt = procdrcode " & _
> "WHERE enterprsphysnid = " & intenterprsphysnid & " " & _
> "GROUP BY enterprsphysnid, procdrcode, tableresult " & _
> "ORDER BY tableresult "
>
> Set physnproc_rs = ODSDev_CGuser.Execute(strSQLProfileProcdr)
>
> If Not physnproc_rs.EOF Then
>
> '***** Build the Physician's procedure table. *****
> strphysnprocdr_table = "<TABLE width='550' border='1' cellpadding='2'
> cellspacing='0'>"
> strphysnprocdr_table = strphysnprocdr_table & "<tr>" & vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "<th><font face='arial'
> size='2'>Remove Procedure</font></td>" & vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "<th><font face='arial'
> size='2'>Procedure Description</font></td>" & vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "</tr>" & vbCRLF
>
> '***** Set variable to blank to ensure it is empty before populating
it.
> *****
> strphysnprocdr = ""
> '***** Start loop for all procedures associated with the physician id.
> *****
> Do While Not physnproc_rs.EOF
> strphysnprocdr_table = strphysnprocdr_table & "<tr>" & vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "<td align='center'><font
> face='arial' size='2'><input type='checkbox' name='delete_checked_proc'
> value='" & physnproc_rs("procdrcode") & "'></font></td>" & vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "<td align='left'><font
> face='arial' size='2'>" & physnproc_rs("tableresult") & "</font></td>"
&
> vbCRLF
> strphysnprocdr_table = strphysnprocdr_table & "</tr>" & vbCRLF
>
> '***** Set variable to a comma delimited string for using in the
updated
> stored procedure above. *****
> strphysnprocdr = strphysnprocdr & physnproc_rs("procdrcode") & ", "
> physnproc_rs.MoveNext
> Loop
> strphysnprocdr_table = strphysnprocdr_table & "</table>" & vbCRLF
> '***** Remove the comma at the end of the last record. *****
> strphysnprocdr = left(strphysnprocdr, len(strphysnprocdr) - 2) & " "
> End If
>
> Here is my HTML code:
>
> <tr>
> <td width="10">&nbsp;</td>
> <td align="left" colspan="5"><font face="arial" size="2">To add another
> procedure to your physician record select a new procedure from the
> dropdown box below then click the ADD PROCEDURE
> button.</font><br><br></td>
> </tr>
> <tr>
> <td width="10">&nbsp;</td>
> <td align="left" name="procdrdescr"><%=strProcdrComboBox%><br><br></td>
> </tr>
> <tr>
> <td width="10">&nbsp;</td>
> <td align="left"><input type="submit" name="submit" value="Add
> Procedure"><br><br><br></td>
> </tr>
$subst('Email.Unsub').



  Return to Index