471,311 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

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

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.
Apr 3 '08 #1
2 1944
It sounds like you might be looking for the PrepareCommand method. After
that, you basically set the parameters for each loop iteration and call the
ExecuteNonQuery method to run the command.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
"TheSteph" wrote:
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.
Apr 3 '08 #2
TheSteph wrote:
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 ?
If the parameter values haven't changed, you can just execute it again.
If they have changed, you would need to change the parameter values first.
So for instance, you could do

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


Apr 4 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.