Is it possible to "cache" the "parameterised" SQL text sent by SqlCommand.ExecuteNonquery() ?

  • Thread starter Thread starter TheSteph
  • Start date Start date
T

TheSteph

Hi

I have a SQLCommand that do updates on a table.

I have a loop where I set the parameters then I call ExecuteNonQuery.

For .

{
. Set the SQLCommand's Params Values;
. SQLCommand.ExecuteNonQuery();
}

Is it possible to "cache" the SQL text sent by Calling ExecuteNonQuery() and
then execute the whole "cached SQL text" in one command ?


Something Like that :

StringBuilder Sb = new StringBuilder();
For.
{
. Set the SQLCommand's Params Values;
. Sb.Append(SQLCommand.GetExecuteNonQueryCmd() + " \n\n");
// GetExecuteNonQueryCmd() don't exists. It's to illustrate the
principle I'm looking for.
}
SqlCommand Sc = New SqlCommand();
Sc.CommandText = Sb.Totring();
Sc.Executenonquery();


Thanks for your help !


Steph.
 
TheSteph said:
Hi

I have a SQLCommand that do updates on a table.

I have a loop where I set the parameters then I call ExecuteNonQuery.

For .

{
. Set the SQLCommand's Params Values;
. SQLCommand.ExecuteNonQuery();
}

Is it possible to "cache" the SQL text sent by Calling
ExecuteNonQuery() and then execute the whole "cached SQL text" in
one command ?

Parameters aren't substituted into the query text, they are sent alongside
as binary data and the query text just contains placeholders. This is why
using parameters protects against SQL injection attacks.
 
Back
Top