如果您只想直接访问此特定功能:
public Object MyFunc(String txt_text)
{
Object result = null;
String connectionstring = "DataSource=.\SQLEXPRESS;"
+ "Initial Catalog=DEMO;"
+ "Integrated Security=True"; // or whatever you use....
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("SELECT dbo.Myfunc(@p1)", connection))
{
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@p1", txt_text);
result = command.ExecuteScalar();
}
}
return result;
}
这将建立与数据库的连接并执行该标量值函数,然后将结果放入result
. 这将任何其他数据库基础设施排除在外,只允许您直接调用您的 SQL 函数。