Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return a value from VFP stored proc
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01526420
Message ID:
01526756
Vues:
57
J'aime (1)
>>>Hi all, I'm trying to return a value from a VFP sp to my .NET app without success my sp is shown below
>>>
>>>
>>>proc UpdateName
>>>Lparameters Name,ID
>>>
>>>Update MyTable ;
>>>set MyName = Name where MyID = ID
>>>
>>>Return _tally
>>>
>>>EndProc
>>>
>>>
>>>
>>>I'm using a Command.ExecuteNonQuery() statement which is supposed to return the number of records affected by the query but always returns 1. If I remove the return statement it makes no difference at all.
>>
>>I usually return a string (an XML string) from my VFP sp when calling it from ASP.NET. And it works. Maybe you could try convert the value you are trying to return into a char type.
>>
>>HTH.
>
>Hi Dmitry, can you show me how you return and retrieve the return value from your sp please ? - calling my sp from the vfp command window works a treat but I need it to work from a WinForms app

Here is a complete code from a method in my asp.net class that calls a VFP stored procedure:
public static string GetUserInformation( string cCookie, string[] aUserInfo )
{

    string cGpmDatabaseFolder = BizObject.GetGpmDatabaseFolder();
    string strDataLocation    = cGpmDatabaseFolder + BizObject.GetGpmDatabaseName();
    string connectionString = "PROVIDER=VFPOLEDB.1;" + "DATA SOURCE=" + strDataLocation + ";UID='';PWD=''";
    string commandText = "SP_GETUSERINFO";

    OleDbCommand oCommand = new OleDbCommand();
    OleDbConnection OleDbConn2Vfp = new OleDbConnection(connectionString);
    OleDbConn2Vfp.Open();
    oCommand.Connection = OleDbConn2Vfp;
    oCommand.CommandText = commandText;
    oCommand.CommandType = CommandType.StoredProcedure;
    oCommand.Parameters.AddWithValue( "@CookieId", cCookie );

   string strReturnXml = "";
   string strErrorMessage = "";

   try 
   {
	strReturnXml = (string) oCommand.ExecuteScalar();
   }
   catch (Exception e)
  {
                strErrorMessage = "Failed to execute Stored Procedure: " + e.Message;
   }
  finally 
  {
         OleDbConn2Vfp.Close();
  }

//==============================================================
// Parse XML returned from SP and extract User Information
//==============================================================
 if (strReturnXml.Length > 0)
    {
	XmlDocument xdoc = new XmlDocument();
	xdoc.LoadXml( strReturnXml );
try 
{
	XmlNode objNode = xdoc.SelectSingleNode("/USERINFO/USER_NAME");
	aUserInfo[0] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_EMAIL");
	aUserInfo[1] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_CC");
	aUserInfo[2] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_PHONE");
	aUserInfo[3] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_BLDG");
	aUserInfo[4] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_FLOOR");
	aUserInfo[5] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_ROOM");
	aUserInfo[6] = objNode.InnerText.ToString();
	objNode = xdoc.SelectSingleNode("/USERINFO/USER_SITE");
	aUserInfo[7] = objNode.InnerText.ToString();

                    if (aUserInfo.Length > 7)
                    {
                        objNode = xdoc.SelectSingleNode("/USERINFO/FIRST_NAME");
                        aUserInfo[8] = objNode.InnerText.ToString();
                        objNode = xdoc.SelectSingleNode("/USERINFO/LAST_NAME");
                        aUserInfo[9] = objNode.InnerText.ToString();
                    }

}
   catch
{
           strErrorMessage = "Error Processing XML returned from VFP SP";
}
}
return (strErrorMessage);

}
Please let me know if you have any question. I know this code pretty long but hopefully you find find how to apply it for your case.

HTH.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform