Below is my SQL query :
select *
from Table
where col1 = @param1 and col2 = @param2
Now I want to execute that SQL query, but I am just interested in getting columns from the query, not any records.
I know I can manipulate this SQL query by finding and removing all parameterized parameters but I am just thinking that is there any way to ignore all this parameters and just execute (select * from Table
).
This is how I am doing it right now :
TCommand cmd = new TCommand();
cmd.CommandText = sqlQuery;
cmd.Connection = connection;
using (var reader = cmd.ExecuteReader())
{
reader.Read();
var columns = reader.GetSchemaTable().AsEnumerable()
.Select(col => col["ColumnName"].ToString())
.ToArray();
return columns;
}
I am getting this error :
Must declare the scalar variable "@param1"
I want to ignore this parameter while executing the SQL query. Is there a way to tell ADO.NET to ignore my query parameter and just execute the query?