Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFPOLEDB, Update and Delete statements?
Message
From
27/10/2003 09:50:25
 
 
To
27/10/2003 08:24:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00842248
Message ID:
00842929
Views:
25
Cetin,

Yes. I am working from within the .net framework. C# is not my native programming language (vfp is) but I find that your examples in vfp were priceless. The info you have provided here is excellent but I must throw in a minor complication. I an working with older fpw26 *FREE* tables that hav no associated dbc. Therefore, the *STORED PROC* example will not help me send UPDATE, INSERT, or DELETE commands to the tables.

Any thoughts?
PS You have certainly provided more useful info regarding vfp as a datastore for .net than any other UT participant. Sure, everyone else give examples of SELECT statements for retrieving data but no one has provided anything for manipulating the actual data in a free table, which is acting as a datastore for an app running in the .net framework. Your contribution towards this end is be priceless and should be published as a KB article. It would be a source of info greatly needed to bring new life to older fpw26 applications. It is also necessary for those newer vfp apps that have free tables in the datastore.

Thank you ever so much,
You continue to be a much needed and appreciated source of info an inspiration,

Thanx,
DR.G (Neil)

>I thought you were asking from within VFP.
>C# samples :
>Simple insert :
>
>  string strConn =
>    "Provider=VFPOLEDB.1;Data source=c:\\myPath\\testdata.dbc;";
>  OleDbConnection cn = new OleDbConnection(strConn);
>  cn.Open();
>  OleDbCommand cmd = cn.CreateCommand();
>  cmd.CommandText = "set null off";
>  cmd.ExecuteNonQuery();
>  cmd.CommandText = "insert into customer (cust_id) values ('C#INS')";
>  cmd.ExecuteNonQuery();
>
>
>Stored procs insert :
>
>private int addCustomer(string cName, string cEmail, string cPassword)
>	{
>		string lcConStr =
>          "Provider = VFPOLEDB;Data Source=C:\\VFP8TEST\\testme.dbc;";
>		OleDbConnection loConnection = new OleDbConnection(lcConStr);
>		loConnection.Open();
>		OleDbCommand loCommand1 = new OleDbCommand();
>		loCommand1.Connection = loConnection;
>		loCommand1.CommandText = "SET NULL OFF\r\nSET DELETED ON";
>		loCommand1.ExecuteNonQuery();
>
>		OleDbCommand loCommand = new OleDbCommand();
>		loCommand.Connection = loConnection;
>		string lcStoredProc = String.Format(
>                        "CustomerAdd('{0}','{1}','{2}')",
>			cName,cEmail,cPassword);
>		loCommand.CommandText=lcStoredProc;
>		loCommand.CommandType=CommandType.StoredProcedure;
>		
>		int liRetValue = (int)loCommand.ExecuteScalar();
>		loConnection.Close();
>
>		return liRetValue;
>	}
>
etc.
>There are other things like OleDbInsertCommand, OleDbDeleteCommand, OleDbUpdateCommand, OleDbSelectCommand objects. Using them you create parametric commands, but I'm not really sure if you're asking ADO.NET code or VFP code.
>
>If you mean you want to directly use ADO.NET from within VFP I don't know if you ever can do that. There are differences between ADO and ADO.NET and currently it's both a huge subject + partially over my knowledge :)
>Cetin
>
>>Cetin,
>>
>>Isn't **oConn = CreateObject('Adodb.connection')** for the old ADO and not the new ado.net?
>>I am confused. Maybe a little example woould help me.
>>
>>Thank you,
>>Neil
>>
>>
>>>Same. Include the fullpath to the free table. You might use any dbc as the datasource (ie: testdata.dbc).
>>>Cetin
>>>
>>>>Thank you Cetin,
>>>>
>>>>I now understand how the execute method enables us to send SELECT statements and commands, such as UPDATE, to the the datastore via ADO. Thank you for the example. Could you please suggest a scheme, and some code of course, for sending commands to a fpw26 free table, acting as a datatstore, in an **ado.net** set up.
>>>>
>>>>Regards,
>>>>Neil
>>>>
>>>>>>Hi,
>>>>>>
>>>>>>Can someone please give me an example of how I could DELETE and UPDATE a record in a vfp table while I am connected to the table via VFPOLEDB? Please use tastrade dbc as an example please.
>>>>>>
>>>>>>
>>>>>>Regards,
>>>>>>Neil
>>>>>
>>>>>Hi Neil,
>>>>>This is a way :
>>>>>
>>>>>
>>>>>Local oConn as adodb.connection, ;
>>>>>	oRS as ADOdb.Recordset, ;
>>>>>	lcCOnnStr as String
>>>>>oConn = CreateObject('Adodb.connection')
>>>>>lcConnStr = 'Provider=VFPOLEDB.1;Data source='+;
>>>>>  Sys(5)+Curdir()+'testdata.dbc'
>>>>>With oConn
>>>>>  .Open(lcConnStr)
>>>>>
>>>>>  oRS = .Execute('select * from customer')
>>>>>  ShowMe('Customer table', oRS)
>>>>>
>>>>>  .Execute('set deleted on')
>>>>>  .Execute('delete from customer where cust_id = "B"')
>>>>>  oRS = .Execute('select * from customer')
>>>>>  ShowMe('Customer table - After Deleted(ansi on,default)', oRS)
>>>>>
>>>>>  .Execute('set ansi off')
>>>>>  .Execute('delete from customer where cust_id = "B"')
>>>>>  oRS = .Execute('select * from customer')
>>>>>  ShowMe('Customer table - After Deleted(ansi off)', oRS)
>>>>>
>>>>>  .Execute('update customer set maxordamt = maxordamt + 1000')
>>>>>  oRS = .Execute('select * from customer')
>>>>>  ShowMe('Customer table - After update', oRS)
>>>>>
>>>>>  .Execute('update customer set maxordamt = maxordamt - 1000') && restore
>>>>>  oRS = .Execute('select * from customer')
>>>>>  ShowMe('Customer table - After restore', oRS)
>>>>>
>>>>>  .Close
>>>>>endwith
>>>>>
>>>>>
>>>>>
>>>>>Function ShowMe
>>>>>Lparameters tcCaption,toRecordset
>>>>>oForm = Createobject('myForm', tcCaption,toRecordset)
>>>>>oForm.Show
>>>>>Read Events
>>>>>Endfunc
>>>>>
>>>>>Define Class myform As Form
>>>>>  Height = 450
>>>>>  Width = 750
>>>>>  Name = "Form1"
>>>>>
>>>>>  Add Object hflex As OleControl With ;
>>>>>    Top = 10, Left = 10, Height = 430, Width = 730, Name = "Hflex", ;
>>>>>    OleClass = 'MSHierarchicalFlexGridLib.MSHFlexGrid'
>>>>>
>>>>>  Procedure Init
>>>>>  Lparameters tcCaption,toRecordset
>>>>>  This.Caption = tcCaption
>>>>>  This.hflex.Datasource = toRecordset
>>>>>Endproc
>>>>>  Procedure QueryUnload
>>>>>  Clear Events
>>>>>Endproc
>>>>>Enddefine
>>>>>
>>>>>PS: Didn't use tastrade but testdata. Tastrade not only have triggers that'd fail for a simple sampling worse it has trigger code that's assuming it's always running from within tastrade.app.
>>>>>Cetin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform