RedAces
RedAces

Reputation: 317

Alternate meaning of SqlCommand's 1st parameter

According to MSDN, the default meaning of the 1st parameter of SqlCommand(String, SqlConnection) is a string of that contains the query to the specified database connection such as

String = "INSERT INTO abc(id, name) VALUES(param1, param2)";

I found this in someone else's code:

SqlCommand cmd = new SqlCommand("rp_air_etg", sql_database_connection);

Does this mean "cmd" is implicitly importing query from a SQL-script?

However, I couldn't find a file with the name "rp_air_etg" anywhere in the solution or the project folder.

Upvotes: 0

Views: 88

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

First parameter is assigned to CommandText property which can be SQL statement, table name or stored procedure to execute at the data source. That is shown in remarks section of SqlCommand constructor - you can see that CommandText initial value is equal to cmdText parameter. And here is implementation:

public SqlCommand(string cmdText, SqlConnection connection) : this()
{
    this.CommandText = cmdText;
    this.Connection = connection;
}

So, in your case it is either table name or stored procedure name.

Upvotes: 2

Related Questions