×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

From relations between Views and Tables.

From relations between Views and Tables.

From relations between Views and Tables.

(OP)
I want to display a one-to-many relationship within a form using a grid for the many end.  This is easy if both ends are tables, however the single end of the relationship is a view.  Is this possible?  Please help.

The MS Help implies you can create a temporary index on a view and also you can set up a relationship between tables and views(?) at runtime.  Is this the way to go about it or should I be using SQL with a filter to populate the grid somehow.

An example of what I'm trying to do is display the children of a person, as well as linking into other tables to pull in additional data about that person.  The children of course, have their own entries in the same table as their parents.

Many Thanks Andy.

RE: From relations between Views and Tables.

(OP)
Sorry, forgot to mention I'm running VFP 6.0 on both 98 and NT.

Also can anybody recommend a book, I'm an experienced C++ programmer, but have just seen the light (FoxPro!).  Can you believe, not one is sold in the main book shops of my two local university cities!

Thanks Again,

Andy.

RE: From relations between Views and Tables.

1. I would copy the information in the SQL View into another SQL statement only redirect the output to a Temp.dbf or cursor and then  print the temp/cursor dbf

2. For info on Books see: http://www.Hentzenwerke.com/

David W. Grewe
Dave@internationalbid.net

RE: From relations between Views and Tables.

(OP)
Thanks Dave,

I was hoping to use the view to update the base tables.  If I copy into a temp table/cursor, I will loose this ability and I assume will have to update the base tables manually from the cursor (that sounds bad!).

Am I asking too much of FoxPro, or am I just not approaching the problem from the right direction.  I'm sure its the latter!

Also would you mind indicating which of the books you recommended is best for this level of problem.

Many Thanks, Andy.

RE: From relations between Views and Tables.

Yes you can do it just as you said.  Set your relations as you stated with your temp index on the view (parent) if you like.  You may want to place them in the DataEnvironment(DE) of your form and set their relations there.  You can then drag fields from the parent table to the form to create the default control for each field's datatype, lavel included and drag the entire child table which will make a grid by default with its properties set to act as a child to the parent specified in the DE.  
VFP also has builders for controls which are quite helpful.  There is a builder in the toolbox and also available in the right click menu of the control.  Right click the grid for example and you will find a very helpful tool.
Congratulations on finding VFP.  You should admire its blazing speed.  AFA a book the Developers Guide from MS isn't bad.  Search 'FoxPro' at Amazon.com or read descriptions of books at the link Dave gave you above for foundational level info.  Good luck and post any questions you may have.

John Durbin
john@johndurbin.com

ICQ #9466492
ICQ VFP ActiveList #73897253

RE: From relations between Views and Tables.

(OP)
Thanks John, I am a fan of the builder and drag-n-drop field to form, capabilities on VFP 6.0 you have mentioned.  I found them out for myself just by playing with the IDE - very intuitive!

I'm probably being a bit dim here, but how do you incorporate a temporary index into the DE for the form?  I thought only persistent tables/indexes could be represented here.

RE: From relations between Views and Tables.

Your view is persistent in that it resides in a DBC.  In AfterOpenTables() of the DE you can SELECT your view and create an index or just do it in code or a method/event of the form somewhere like Init().  The form is initialized only after all contained objects including the DE have successfully initialized so you can do it there.
There are other, perhaps better ways to accomplish what you're doing however.  For instance you could requery your view on the primary key of the table it acts as a child of.  So say you're skipping thru a customer table (parent), you typically create a view of CustomerOrders (child), etc with a foreign key which matches the primary key of the customer table.  On record movement you simply Requery() your view.  
The help on views is really quite good in VFP.  See Primary & Foreign Keys, Parametized Views, NoDataOnLoad.  foxdev (Robert Bradley) is very good with this stuff, especially C/S & SQL, maybe you can ask him to create a FAQ if he hasn't already  :o

John Durbin
john@johndurbin.com

ICQ #9466492
ICQ VFP ActiveList #73897253

RE: From relations between Views and Tables.

Thanks John,
That is what I get for answering a VisualFoxPro question when I do not know it as well as FPW.   

David W. Grewe
Dave@internationalbid.net

RE: From relations between Views and Tables.

(OP)
Jon,

Thanks, I've managed to create the temp index solution in the command window!  I'll try doing it in the form shortly.

I had played with Parameterized Views as per your second solution, however I could not get the child view to update with new parameter values.  It stays with the first input value present when the form is initialisd.  I assume a requery is in order (if so how?).  Also should the view parameter be set to the index of the parent table (=table.index?).  This didn't seem to work - I also tried a form property variable but this would need updating each time the parent table record pointer is moved.

I've noticed I should really be in the Visual FoxPro forum, which I'm now subscribing to now also.  I'm well impressed with both though.

Again Many Thanks for you help, Andy.

RE: From relations between Views and Tables.

>Thanks, I've managed to create the temp index solution in the command window!  I'll try doing it in the form shortly.

Same thing there.

>I had played with Parameterized Views as per your second solution, however I could not get the child view to update with new parameter values.  It stays with the first input value present when the form is initialisd.  I assume a requery is in order (if so how?).

You have to store the new value to your parametized value before each requery.  Probably the easiest place to issue a requery is in the grid's Refresh() event.

>Also should the view parameter be set to the index of the parent table (=table.index?).  

You're kinda mixing up indexes with keys.  Your parent table relates to your child.  A parent doesn't need to indexed at all though it typically is.  You can index on various fields and expressions.  In a 1 to many relation the parent tables key is a unique identifier of each row in the table.  Typically this is a single field such as cust_id.  The best solution though is a 'surrogate' key which is a field such as custkey with its value to have no other meaning in the table than as a unique identifier of each record.  That way if you change cust_id your primary key is left untouched.  So if you are indexing on both the answer is only if the field of the parent table you indexed on has an equivalent in the child's.  If your parent's primary key is cust_id or custkey then your parameter must equal it.

>This didn't seem to work - I also tried a form property variable but this would need updating each time the parent table record pointer is moved.

Yes that's right.  No getting around it w/o a set relation whether the view is parametized or not.  Perhaps we should drop the parametized here anyways though.  A parametized value allows you to prompt the user for the value if it is not supplied which you are evidently not doing here.  Just make your WHERE MyChildTable.cust_id = MyParentTable.cust_id. and see what you get.  You still need to requery with each movement of your parent table.  For starters you may want to just experiment with tables.  View are great for viewing more than 1 table in a single entity like a grid control or browse window and for updating remote data sources like SQL Server, etc.  Are you joining more than one table in your view?

>I've noticed I should really be in the Visual FoxPro forum, which I'm now subscribing to now also.  I'm well impressed with both though.

Ya both are great and are fun.  I'm still chicken schmidt to answer 2.6 questions cuz well I am not good at it.  At least Dave has guts to try to help with VFP.  :)  More than I can say for me with 2.6  :o   
Andy, do you have any books?  I encourage you to get at least one book (though they are on the help files in entirety!)  What do you have?  Studio?  You have the help files right?  I'm just wondering if we have a mutual reference point here as it is much more thorough and accurate than I may be here.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close