Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Indirect reference to variables
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 2.0
OS:
Windows 2000
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01143616
Message ID:
01143645
Vues:
11
This message has been marked as the solution to the initial question of the thread.
>I have a screen of selection criteria for selecting data from a table. The user is not required to select a value for each criterion. I build a condition statement for my SQL command based on the non-blank selection criteria. I want to use the IDbParameter type to create parameters. I don't want to create a separate if statement for every possible combination of non-blank parameters.
>
>I would like to use a counter to name my parameter variables. For example:
>
>
>int ICounter;
>for (ICounter = 1; ICounter <= 4; ICounter++)
>{
>  string  paramString = "param" + ICounter.ToString();
>}
>
You can do something like this:
StringBuilder SB = new StringBuilder();  // This is your select string...initialize it as needed
string ParamString;

IDbDataParameter[] Params = new IDbDataParameter[4]; // This is hard-coded to 4, but you can use a variable instead
mmDataAccessBase DAO = this.GetDataAccessObject();

for (int ICounter = 0; ICounter <= 4; ICounter++)
{
	ParamString = DAO.ParameterPrefixChar + "Param" + ICounter.ToString();
	// This is the key to creating parameters to be passed...replace the 0 with the real value
	Params[ICounter] = this.CreateParameter(ParamString, 0);
	// NOTE: Add code here to concatenate the parameters to your SELECT statement in the StringBuilder
}

// Note that an IDbDataParameters array is passed rather than passing individual parameters...another key to solving this problem
this.GetDataSet(SB.ToString(), Params);
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform