Calling Functions in SqlCommand

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

Can I use the Sql Server functions in myCommand.CommandText and why?

+5
source share
1 answer

If you mean the custom features of SQL Server . Then yes ; you can use it as usual:

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

The reason it works is because it is because functions are called directly in SQL Server.

+12
source

All Articles