Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling VFP Stored Procedure ?
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00712424
Message ID:
00712439
Views:
21
You need to change your C# because the current VFP OLEDB provider does not accept the CommandType of StoredProcedure. You need to also create the command string with the parameters placeholders in the function call and define the parameters in the same order as they are to be passed:
using System;
using System.Data;
using System.Data.OleDb;
OleDbConnection oConn = new OleDbConnection(cConnString);
try
{ oConn.Open(); }
catch(Exception oErr)
{ System.Windows.Forms.MessageBox.Show("\n" + oErr.Message + "\n"); }
System.Data.OleDb.OleDbCommand oCmd = new OleDbCommand("PutResult(?,?)",oConn);
oCmd.Parameters.Add(new OleDbParameter("cInputID",OleDbType.Char,60,"cInputID"));
oCmd.Parameters.Add(new OleDbParameter("cInputResult",OleDbType.Char,4096,"cInputResult"));
string cRetVal = oCmd.ExecuteScalar().ToString();
>I have a simple stored procedure in my VFP7 DBC for inserting data into a table. I am trying to execute the stored procedure by passing parameters only. The error I get is
>"
>An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
>"
>
>Why is that?
>
>c# code:
>
>using System;
>using System.Data;
>using System.Data.OleDb;
>OleDbConnection oConn = new OleDbConnection(cConnString);
>try
>{ oConn.Open(); }
>catch(Exception oErr)
>{ System.Windows.Forms.MessageBox.Show("\n" + oErr.Message + "\n"); }
>System.Data.OleDb.OleDbCommand oCmd = new OleDbCommand();
>oCmd.Connection = oConn;
>oCmd.CommandType = CommandType.StoredProcedure;
>oCmd.Parameters.Add(new OleDbParameter("cInputID",OleDbType.Char,60,"cInputID"));
>oCmd.Parameters.Add(new OleDbParameter("cInputResult",OleDbType.Char,4096,"cInputResult"));
>string cRetVal = oCmd.ExecuteScalar().ToString();
>
>
>
>VFP Stored Procedure:
>
>	Function PutResult
>	Lparameters ;
>		cInputID as String , cInputResult as String
>		If VarType(cInputID) != "C"
>			Return 0
>		EndIf
>		If VarType(cInputResult) != "C"
>			Return 0
>		EndIf
>		If Len(cInputID)< 1
>			Return 0
>		EndIf
>		If Len(cInputID)> 24000
>			Return 0
>		EndIf		
>		Local cIns as String
>		cIns =	"insert into result(cid,mdata) " + ;
>				"values " + ;
>				"('" + cInputID + "','" + ;
>				cInputResult + "')"
>		&cIns
>		Return 1
>	EndFunc
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform