Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP 7.0 need to add a record without opening table

Status
Not open for further replies.

bettyfurr

Technical User
Mar 12, 2002
371
US
Is it possible to add a record without opening the table?
 
You can use an INSERT INTO SomeTable but it will automatically open SomeTable when you do it.

Dave S.
 
To answer the specific question, no. By definition any file must be opened to read it or write to it - whether it's a DBF or not.

Rick
 
Use the insert-sql statement to do it.

EX:
insert into path\tablename (field1,field2);
values("val1","val2")

should work
 
Dan,
While you don't have to open the file using this technique, FoxPro does, and as Dave points out FP doesn't close it. So either you'll have to explicitly close it, or if you are in a Private data session it will be closed when it's closed.

Rick
 
how do you open a private data session? I have not used one except in a report.

Betty
 
Hi Betty,

if you create an ODBC connection to your database
you can insert in your table without opening it

cSql="INSERT INTO YourTable (field1...) VALUES (val1...)"
sqlexec(nConnHandle,cSql)

ODBC open your table, insert records and close it.

But why?? Andrea C.P.
Italy [atom]
 
HI Betty,

1. A form can be set with private data session by setting the forms property..
DataSession = 2 && means private datasession. By default this is 'default data session'.

2. When you want to insert a record in a particular table and you dont want that to remain open after opening it.. appending the record ... then you can do the following in the recording procedure..

USE myTable IN 0 ALIAS myTable
INSERT INTO myTable FROM MEMVAR && or whatever
USE IN myTable && this closes the table

The above does not disturb the current alias and so you dont have to worry about the current selected table.

Hope this helps you :)

ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hi Betty,

There are four types of classes that use a datasession:
- The session class (available since VFP 6.0)
- A form
- A form set
- A toolbar

If you want to instantiate a session without an object bound to it, use the session class.

If you have an object (Form, Formset, Toolbar) and you close it (by releasing the object), the private datasession will be closed automatically, closing your cursors (views, cursors, tables) with it.

HTH,
Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
A lot of times one of my team come and ask me a question how to ……
After some discussion even after we find a way to do it, we find out that this is not the best way to do it. My alert for this kind of situations is to try to reverse the logic behind how things work, this post is an example for this situation.
Natively, Fox will not do it for you but it is possible any ways with some pain and C code. But my advice is to review your design and see what led you to this unusual situation. I believe you will find some thing not right

Thanks
Walid Magd
Engwam@Hotmail.com
 
I know you guys want to know. I have a system that allows different projects to be build. Each project is contained within a master table and does not get its unique table. Each task has tables created using structures that is named project+task. One of the tables gets the default information that can be later be extracted and put in the project+task table. The project manager can decide that the default info will not fully meet their needs and add to a project+task table. However, they wanted this additional information added to their default information at the project level not the project+task level.

You have convinced me to rethink this table to be at the project level and not project +task level.

Thank for all you guys input.

Betty
 
It's still not clear what this situation has to do with "Adding a record to a table without opening the table." What prevents you from opening the table? If nothing, just do an "INSERT INTO ..." then close the table using "USE IN tablename". If the trouble is that a different program is using the table already, make both programs non-exclusive ("SET EXCLUSIVE OFF").
 
All of the code to update the record is in a procedure that has as field pointer generic Alias not the filename. I would have to duplicate the code for an insert, which is info coming from 3 tables and fields being combined. The generic alias is already in use by the working project+task.

I was looking for the easy way out. Add to inactive tables. This turns out not be a good idea. I was hoping for a low-level table code that could do that.

I hope this explains it, wgcs.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top