Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Sql Server functions in myCommand.CommandText and why?

like image 404
F11 Avatar asked Feb 24 '13 03:02

F11


1 Answers

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.

like image 163
Mahmoud Gamal Avatar answered Sep 24 '22 20:09

Mahmoud Gamal