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 Sql Server functions in myCommand.CommandText and why?
Advertisement
Answer
If you mean, SQL Server user defined functions. Then, yes; you can use it normally like:
myCommand.CommandText = "SELECT fn_Yourfunctionname(@parameternames)"; myCommand.CommandType = CommandType.Text; myCommand.Parameters.Add(new SqlParameter("@parameternames", ...
The reason it works is because this is the way that functions are called in SQL Server directly.