Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to create DataSet from SqlSelect with parameter?
Message
De
29/11/2007 14:34:11
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01272138
Message ID:
01272173
Vues:
12
>>I have created data reader with parameters many times but now I need to create a dataset and I am lost.
>>
>>Here is an example:
>>
>>
>>OleDbConnection oDbConnection = new OleDbConnection
>>(connectionString);
>>
>>string strSqlCommand = "select * MYTABLE where MYFIELD(?)";
>>
>>OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSqlCommand,
>>oDbConnection);
>>
>>DataSet dsMyTable = new DataSet();
>>
>>objAdapter.Fill(dsMyTable, "tblMyTable");
>>
>>
>>
>>Somewhere above I have to specify parameter for field MYFIELD but I don't know how and where.
>>
>>Thank you in advance for any help.
>
>
>I found out that I probably need to add the parameret to the Adapter object, as following:
>
>
>objAdapter.GetFillParameters()[0].Value = nMyValue;
>
>
>But I get an error on this line that index is invalid. So I think I need to find a way to specify that the adapter takes so many paramenters. I can't find how to do it so far.

Dmitry,
I usually use parameters with SPROCS instead of with straight SQL, so I don't know exactly what you need to do, but I think you are specifying your parameter incorrectly in your SQL.

Try changing you SQL to something like this:
"select * MYTABLE where MYFIELD = @MyFieldParm";
and your code to something like this:
objAdapter.GetFillParameters()["@MyFieldParm"].Value = nMyValue;
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform