SqlDataAdapter question

  • Thread starter Thread starter Paolo
  • Start date Start date
P

Paolo

I am configuring a SqlDataAdapter as follows:

private void ConfigureAdapter(out SqlDataAdapter dAdapt)
{
dAdapt = new SqlDataAdapter("Select * From Activities", cnString);

// Obtain the remaining Command objects dynamically at runtime
// using the SqlCommandBuilder.
SqlCommandBuilder builder = new SqlCommandBuilder(dAdapt);
}

All the examples I see of the use of SqlDataAdapters show a single Select
command (e.g. 'select * from <database>') as above.

Is it possible, in the same program, to use more than one SELECT statement
at different times? For example I have set the initial SELECT as shown above.

If, at a different point in my program, I want to change the Select command
to, say, 'select <col name> from <database> where...' to return a different
subset of the data, how do I do it?.



Thanks
 
Paolo said:
I am configuring a SqlDataAdapter as follows:

private void ConfigureAdapter(out SqlDataAdapter dAdapt)
{
dAdapt = new SqlDataAdapter("Select * From Activities",
cnString);

// Obtain the remaining Command objects dynamically at runtime
// using the SqlCommandBuilder.
SqlCommandBuilder builder = new SqlCommandBuilder(dAdapt);
}

All the examples I see of the use of SqlDataAdapters show a single Select
command (e.g. 'select * from <database>') as above.

Is it possible, in the same program, to use more than one SELECT statement
at different times? For example I have set the initial SELECT as shown
above.

If, at a different point in my program, I want to change the Select
command
to, say, 'select <col name> from <database> where...' to return a
different
subset of the data, how do I do it?.

You can change the Select statement at any time through the
SelectCommand in the DataAdapter:

dAdapt.SelectCommand.CommandText = "Select * from anothertable";

Notice that this doesn't automatically change the UpdateCommand,
InsertCommand and DeleteCommand, so if you need them you will have to apply
a new SqlCommandBuilder.
 
Alberto: thanks for the clarification.

Alberto Poblacion said:
You can change the Select statement at any time through the
SelectCommand in the DataAdapter:

dAdapt.SelectCommand.CommandText = "Select * from anothertable";

Notice that this doesn't automatically change the UpdateCommand,
InsertCommand and DeleteCommand, so if you need them you will have to apply
a new SqlCommandBuilder.
 
Back
Top