1

我正在使用 Visual Foxpro 8.0 数据库。下面的过程我用来根据条件匹配从数据库返回记录,但它引发了错误:

“功能未实现。”

Foxpro 程序 -------------

PROCEDURE FX_Proc_ValidateUser (paramUserName AS Character, paramPassword AS Character)
LOCAL VarUserName AS Character, varXml
VarUserName = IIF(VARTYPE(paramUserName)!="N","",paramUserName)
LOCAL VarPassword AS Character
VarPassword = IIF(VARTYPE(paramPassword)!="N","",paramPassword)
SELECT userinfoid, ;
        username, ;
        password ;
FROM tm_userinfo.dbf ;
WHERE username = VarUserName AND password = VarPassword ;
INTO CURSOR procResult  
varXml = ""
CURSORTOXML("procResult","varXml",1,32,0,"1")
RETURN varXml
ENDPROC

调用此过程的前端代码------

string ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\Users\raj\Documents\Visual FoxPro Projects\dbFoxMaster.dbc;Collating Sequence=machine;" providerName="System.Data.OleDb.OleDbConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
OledbConnection objOleDbConnection = new OleDbConnection(ConnectionString);
objOleDbConnection.Open();
OleDbCommand objOleDbCommand = new OleDbCommand();
objOleDbCommand.CommandType = CommandType.StoredProcedure;
objOleDbCommand.CommandText = "FX_Proc_ValidateUser";
objOleDbCommand.Connection = objOleDbConnection;
objOleDbCommand.Parameters.Add("paramUserName", OleDbType.Char).Value = "abc";
objOleDbCommand.Parameters.Add("paramPassword", OleDbType.Char).Value = "123";
var xmlString = oOleDbCommand.ExecuteScalar().ToString();
    DataTable table = new DataTable();
    using (var reader = new StringReader(xmlString))
    {
        var dataSet = new DataSet();

        // creating a dataset from the xml 
        dataSet.ReadXml(reader);
        table = dataSet.Tables[0];
    }

如何使用 OledbCommand 从 foxpro 8.0 存储过程中获取结果集?

4

3 回答 3

3

看起来问题在于您将结果放入数组中,并且只返回数组中的第一项。您应该更改存储过程,以便它使用游标。

VFP9 示例

下面是来自 northwind.dbc 的存储过程示例: 在此处输入图像描述

以下是使用 C# 调用存储过程的示例:

var northwindDbcPath = @"C:\Program Files (x86)\Microsoft Visual FoxPro 9\Samples\Northwind\Northwind.dbc";
var connectionString = "Provider=VFPOLEDB.1;Data Source=" + northwindDbcPath;
var table = new DataTable();

using(var connection = new OleDbConnection(connectionString)) {
    using(var command = connection.CreateCommand()) {
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "CustOrdersDetail";
        command.Parameters.Add("x", 10248);

        var adapter = new OleDbDataAdapter(command);

        adapter.Fill(table);
    }
}

VFP8 示例:(我没有 VFP8 的副本,但我相信这会起作用) 在此处输入图像描述

var northwindDbcPath = @"C:\Program Files (x86)\Microsoft Visual FoxPro 9\Samples\Northwind\Northwind.dbc";
var connectionString = "Provider=VFPOLEDB.1;Data Source=" + northwindDbcPath;
DataTable table;

using(var connection = new OleDbConnection(connectionString)) {
    using(var command = connection.CreateCommand()) {
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "CustOrdersDetail2";
        command.Parameters.AddWithValue("x", 10248);

        connection.Open();      
        // executing stored procedure and getting xml result
        var xml = command.ExecuteScalar() as string;

        connection.Close();

        using(var reader = new StringReader(xml)) {
            var dataSet = new DataSet();

            // creating a dataset from the xml 
            dataSet.ReadXml(reader);
            table = dataSet.Tables[0];
        }
    }
}
于 2013-01-07T21:17:24.410 回答
0

我没有 VFP,我上次使用 VFP 时仍然是 3.0 版...

我会根据这里的规格尝试这样的事情。在这里学习其余的阅读

PROCEDURE insertData (pusername, ppassword)

                    SELECT userinfoid, username, password 
                    FROM tm_userinfo.dbf 
                    WHERE username = pusername AND password = ppassword
                    INTO ARRAY results
     RETURN results
ENDPROC
于 2013-01-05T13:38:04.700 回答
0

Visual Foxpro 存储过程基本上是使用 Visual Foxpro 代码来执行任务,例如在插入或更新或删除时验证列。

例如,您可以将以下代码添加到 VFP 数据库存储过程以验证“状态”列:

PROCEDURE ValidateState()
IF address.state <> [OH]
    MESSAGEBOX([Incorrect State value!], 48, [Invalid State])
ENDIF
ENDPROC

要查询 Foxpro 数据库中的表,您可能需要查看创建本地视图。您可以通过右键单击 foxpro 数据库并选择“新建本地视图”来执行此操作,然后使用查询生成器定义您的视图。在“过滤器”选项卡的“示例”列下,您可以使用“?”定义参数 例如“?用户名”。

下面是从 Foxpro 代码调用视图的方法:

 LOCAL pusername AS Integer   
 pusername = "SomeUserName"    &&Use this to filter the view
 SELECT 0
 USE MyViewName       &&This will call the view and perform the filter.

您还可以使这些视图可更新并针对视图执行插入操作。

于 2013-01-06T01:23:43.007 回答