在SqlCommand中调用函数

public void CreateMySqlCommand() { SqlCommand myCommand = new SqlCommand(); myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; myCommand.CommandTimeout = 15; myCommand.CommandType = CommandType.Text; } 

我可以在myCommand.CommandText中使用Sql Server函数吗?为什么?

如果您的意思是, SQL Server用户定义的函数 。 然后, 是的 ; 你可以正常使用它:

 myCommand.CommandText = "SELECT fn_Yourfunctionname(@parameternames)"; myCommand.CommandType = CommandType.Text; myCommand.Parameters.Add(new SqlParameter("@parameternames", ... 

它工作的原因是因为这是在SQL Server中直接调用函数的方式。