Managing a SQLParameter/ODBCParameter Object

  • Thread starter Thread starter Pierluigi Terzoli
  • Start date Start date
P

Pierluigi Terzoli

Hi everybody,
I have a simple question:
I need to execute the same SQL statement (an Insert one) several times.
This command has some parameters, I'll make an example:
INSERT INTO test (id) VALUES (@id) --> (for SQLServer engine)
So, I'd like to have a SqlParameter collection and every time change the
value of the parameter only.
I didn't find any method to do it.
Do I have to SqlParameter.Clear() the collection and rebuild it every time
??
Thanks in advance, Pierluigi.
 
Hi,

as your parameter collection changes for each execution, you need to change
the values only viz.,

SqlParameter myParameter = new SqlParameter("@MyVar", SqlDbType.VarChar);
myParameter["@MyVar"].Value = "My Value";

// later on

myParameter["@MyVar"].Value = "My 2nd Value";

etc.

Regards

Joyjit
 
You're right, Thanks Joyjit for helping me.
Bye, Pierluigi.

Joyjit Mukherjee said:
Hi,

as your parameter collection changes for each execution, you need to change
the values only viz.,

SqlParameter myParameter = new SqlParameter("@MyVar", SqlDbType.VarChar);
myParameter["@MyVar"].Value = "My Value";

// later on

myParameter["@MyVar"].Value = "My 2nd Value";

etc.

Regards

Joyjit

Pierluigi Terzoli said:
Hi everybody,
I have a simple question:
I need to execute the same SQL statement (an Insert one) several times.
This command has some parameters, I'll make an example:
INSERT INTO test (id) VALUES (@id) --> (for SQLServer engine)
So, I'd like to have a SqlParameter collection and every time change the
value of the parameter only.
I didn't find any method to do it.
Do I have to SqlParameter.Clear() the collection and rebuild it every time
??
Thanks in advance, Pierluigi.
 
Back
Top