Is it allowed?
What I mean is, if I have two queries? Like I need to read a dataset to populate a gridview and other than gridview, in one form.
Is it allowed?
What I mean is, if I have two queries? Like I need to read a dataset to populate a gridview and other than gridview, in one form.
There's nothing wrong with having multiple adapters so long as they're differently named and you duplicate the remainder of the components below the adapter in the data retrieval process with different names than the first set (ie: command, dataset, etc).
Alternately...
If the 2 queries are similar but with one or two differences (ie: same subset of data but with different conditions on the WHERE portion) you can just have a dynamically populated SELECT string and run the ONE set of everything twice with 2 different values... the only thing you'd have to do then is ensure that the population portion (where the data gets put in your form) is separated and the SELECT string is swapped between the reads.
For Example (just gonna use pseudocode for this):
string sqlSelectString = "SELECT * FROM dbName WHERE conditionA";
private void dbConnecting()
{
--insert usual connection setup here--
sqlDataAdapter myAdapt = new sqlDataAdapter(sqlSelectString, connection);
--insert command and dataset population here--
}
private void getFirstPop()
{
dbConnecting();
--insert population of form fields from dataset--
}
private void getSecondPop()
{
sqlSelectString = "SELECT * FROM dbName WHERE conditionB";
dbConnecting();
--insert population of form fields from dataset--
}
Again this is piecemeal pseudocode just to give the logic cus it's now almost 4:15am here :P
Hope it helps :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.