Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need to return a value from VFP stored procedure
Message
De
01/04/2003 06:53:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
00772286
Message ID:
00772326
Vues:
17
>Has anyone had success at retrieving a value returned from a VFP8 stored procedure? Here's my SP code:
>
>
>FUNCTION CustomerAdd(tcName, tcEmail, tcPassword)
>  INSERT INTO Customers ;
>     (cName,            ;
>      cEmail,           ;
>      cPassword)        ;
>    VALUES              ;
>     (tcName,           ;
>      tcEmail,          ;
>      tcPassword)
>
>  RETURN CustomerID
>ENDFUNC
>
>and here's my VB.Net code:
>
>Public Function AddCustomer(ByVal tcName As String, ByVal tcEmail As String, ByVal tcPassword As String) As Integer
>  Dim loConnection As OleDbConnection
>  Dim loCommand As OleDbCommand
>  Dim loCustID As OleDbParameter
>
>  Dim lcConnectString As String
>  Dim liCustomerID As Integer
>
>  lcConnectString = "Provider=vfpoledb;Data Source=" & Server.MapPath(".") & "\Data\ss.dbc;Nulls=1"
>  loConnection = New OleDbConnection(lcConnectString)
>  loConnection.Open()
>
>  loCommand = New OleDbCommand()
>  loCommand.Connection = loConnection
>  loCommand.CommandText = "SET NULL OFF\r\nSET DELETED ON"
>  loCommand.ExecuteNonQuery()
>
>  loCommand = New OleDbCommand()
>  loCommand.Connection = loConnection
>  loCommand.CommandText = "CustomerAdd"
>  loCommand.CommandType = CommandType.StoredProcedure
>
>  loCustID = New OleDbParameter()
>  loCustID = loCommand.Parameters.Add("CustomerID", OleDbType.Integer)
>  loCustID.Direction = ParameterDirection.ReturnValue
>
>  loCommand.Parameters.Add("Name", OleDbType.Char)
>  loCommand.Parameters.Add("Email", OleDbType.Char)
>  loCommand.Parameters.Add("Password", OleDbType.Char)
>
>  loCommand.Parameters("Name").Value = tcName
>  loCommand.Parameters("Email").Value = tcEmail
>  loCommand.Parameters("Password").Value = tcPassword
>
>
>  loCommand.ExecuteNonQuery()
>  loConnection.Close()
>
>  liCustomerID = CInt(loCustID.Value)
>
>  Return liCustomerID
>End Function
>
>
>I'm getting an error on the ExecuteNonQuery() line:
>
>
>System.Data.OleDb.OleDbException: Variable 'Q5P0' is not found.
>
>
>Oddly, the integer after the 'Q' increments every time I run the code.
>
>Strange stuff, don't you think?

I think odd think is .NET. In documentation it says :
"The OLE DB .NET Data Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure. In this case, you must use the question mark (?) placeholder."
Hoever I was never successfull doing so. But this one works (C# but easy to convert) :
private int addCustomer(string cName, string cEmail, string cPassword)
{
 string lcConStr = "Provider = VFPOLEDB;Data Source=...;";
 OleDbConnection loConnection = new OleDbConnection(lcConStr);
 loConnection.Open();

 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;
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform