我在一个名为“StripLead”的模块中编写了一个 ms-access 函数。我做了一个名为“CallFunction”的单行程序。现在,当我从 ms-access 调用此过程时,它工作正常。但是当我从 C# 调用这个过程时,我得到了错误:
表达式中未定义的函数“Striplead”。
ms-access模块代码:
Public Function StripLead(pstrPhrase As String) As String
Dim strFirstWord As String
Dim strReturn As String
Dim intPos As Integer
strReturn = pstrPhrase
intPos = InStr(pstrPhrase, " ")
If intPos > 0 Then
strFirstWord = Left$(pstrPhrase, intPos - 1)
Select Case strFirstWord
Case "A", "An", "The"
strReturn = Right$(pstrPhrase, Len(pstrPhrase) - intPos)
End Select
End If
StripLead = strReturn
End Function
ms-access 过程“CallFunction”(sql视图):
SELECT Customers.ID, Striplead([ContactName]) AS a FROM Customers;
C#代码:
public void CallStoredProcedure(string NewQry)
{
try
{
DataTable tbl = new DataTable();
using (OleDbConnection connection = new OleDbConnection(ConnectionString))
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "CallFunction";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = connection;
using (OleDbDataAdapter adp = new OleDbDataAdapter(cmd))
{
adp.Fill(tbl);
}
}
}
catch(Exception ex)
{
throw;
}
}
请提出方法是否不正确。或者,如果有办法从 C# 调用 ms-access 函数来获取数据。我的目标是从 ms-access 获取修改后的数据并用 C# 填充数据网格。