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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TheSteph

    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.Exec uteNonQuery();
    }

    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(SQLCo mmand.GetExecut eNonQueryCmd() + " \n\n");
    // GetExecuteNonQu eryCmd() don't exists. It's to illustrate the
    principle I'm looking for.
    }
    SqlCommand Sc = New SqlCommand();
    Sc.CommandText = Sb.Totring();
    Sc.Executenonqu ery();


    Thanks for your help !


    Steph.


  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: Is it possible to "cache&quo t; the "parameter ised" SQL text sent by Sql

    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.Exec uteNonQuery();
    }
    >
    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(SQLCo mmand.GetExecut eNonQueryCmd() + " \n\n");
    // GetExecuteNonQu eryCmd() don't exists. It's to illustrate the
    principle I'm looking for.
    }
    SqlCommand Sc = New SqlCommand();
    Sc.CommandText = Sb.Totring();
    Sc.Executenonqu ery();
    >
    >
    Thanks for your help !
    >
    >
    Steph.
    >
    >
    >

    Comment

    • Steve Gerrard

      #3
      Re: Is it possible to "cache&quo t; the "parameter ised" SQL text sent by SqlCommand.Exec uteNonquery() ?

      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.Exec uteNonQuery();
      }
      >
      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.Exec uteNonQuery();
      }




      Comment

      Working...