18.01.2013 Views

Visual Basic 6 Client/Server Programming Gold Book:Table of ...

Visual Basic 6 Client/Server Programming Gold Book:Table of ...

Visual Basic 6 Client/Server Programming Gold Book:Table of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Brief Full<br />

Advanced<br />

Search<br />

Search Tips<br />

To access the contents, click the chapter and section titles.<br />

<strong>Visual</strong> <strong>Basic</strong> 6 <strong>Client</strong>/<strong>Server</strong> <strong>Programming</strong> <strong>Gold</strong> <strong>Book</strong><br />

(Publisher: The Coriolis Group)<br />

Author(s): Michael MacDonald and Kurt Cagle<br />

ISBN: 1576102823<br />

Publication Date: 10/01/98<br />

Search this book:<br />

Previous <strong>Table</strong> <strong>of</strong> Contents Next<br />

Now that we have a convenient place from which to decode values (and potentially to<br />

encode as well), how do we use the table for validation? It is no longer possible to have<br />

referential integrity constraints, because there is no unique key for the database to<br />

validate against. The primary key <strong>of</strong> Data_Dic is dd_type and dd_val combined. dBase<br />

developers will remember that you could validate by hard-coding a portion <strong>of</strong> the other<br />

table’s key—if SQL allowed this, it would look something like:<br />

ALTER TABLE CUSTOMER<br />

ADD CONSTRAINT FK_Val_State<br />

FOREIGN KEY ('SC', cust_st)<br />

REFERENCES DATA_DIC (dd_type, dd_val)<br />

The (‘SC’, cust_st) would be needed, <strong>of</strong> course, so that you could validate cust_st<br />

against dd_val where dd_type = ‘SC’.<br />

So, what is left to accomplish the validation? The obvious answer is to open record sets<br />

from VB to validate our data:<br />

Set arLookup A= New Recordset<br />

Set arCust = New Recordset<br />

' acon is an active connection<br />

arLookup.Open "Select * from data_dic Where dd_type = " & _<br />

"'CC' And dd_val = " & txtCountry.text, acon<br />

If arLookup.BOF = True and arLookup.EOF = True Then<br />

' No records<br />

MsgBox "Invalid Country!"<br />

txtCountry.SetFocus<br />

Exit Sub<br />

Else<br />

' proceed with update<br />

End If

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!