473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 2081
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben | last post by:
Hi! It has been weeks now that I have been trying to fix an error that I encounter everytime it gets to the code at runtime: SQLStmt = "SELECT Sum() As TotalInStock, Sum( * ) AS TotalCost " & _...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.