Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IDbCommand and Parameters.AddWithValue()
Message
 
 
À
20/03/2012 11:00:44
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01538772
Message ID:
01538791
Vues:
32
>>>Hi,
>>>
>>>I am working on a case of replacing what the gurus call "programming to class" with "programming to interface" for the following code:
>>>
>>>First, the code the way it works currently (not with interface)
>>>
>>>OleDbCommand oCommand = new OleDbCommand();
>>>// connectionString is valid string (not shown here)
>>>OleDbConnection oConnection = new OleDbConnection(connectionString);
>>>oConnection.Open();
>>>oCommand.CommandText = "SP_MyProc";
>>>oCommand.CommandType = CommandType.StoredProcedure;
>>>oCommand.Parameters.AddWithValue( "@par1", cPar1 );
>>>
>>>
>>>The following is my replacement code (simplified):
>>>
>>>IDbCommand oCommand;
>>>idbCommand = new OleDbCommand();
>>>// connectionString is valid string (not shown here)
>>>OleDbConnection oConnection = new OleDbConnection(connectionString);
>>>oConnection.Open();
>>>oCommand.CommandText = "SP_MyProc";
>>>oCommand.CommandType = CommandType.StoredProcedure;
>>>oCommand.Parameters.AddWithValue( "@par1", cPar1 );
>>>
>>>
>>>The problem is that in the lower case code the method .AddWithValue has an error:
>>>
>>>'System.Data.IDataParameterCollection' does not contain definition for 'AddWithValue'
>>>
>>>
>>>What am I missing? TIA.
>>
>>I tried to replace method AddWithValue with Add() but Add() only takes one parameter. So I am not sure how to pass the parameter name and the value if I can't use AddWithValue(). Any suggesetions?
>
>Something like:
          IDbCommand idbCommand = new OleDbCommand();
>            IDbDataParameter param = idbCommand.CreateParameter();
>            param.ParameterName = "@par1";
>            param.Value = cPar1;
>            idbCommand.Parameters.Add(param);
Thank you very much.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform