473,473 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SqlDataAdapter question

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 namefrom <databasewhere...' to return a different
subset of the data, how do I do it?.

Thanks
Oct 3 '08 #1
2 1612
"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
>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 namefrom <databasewhere...' 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.

Oct 3 '08 #2
Alberto: thanks for the clarification.

"Alberto Poblacion" wrote:
"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
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 namefrom <databasewhere...' 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.

Oct 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Programatix | last post by:
Hi, I'm working on a WebService project. I'm trying to validate data before they are updated to the database by handling the RowUpdating event for a SqlDataAdapter. The data being handled has...
6
by: goodstart123 | last post by:
For example, the following code works fine without SqlConnection. Any Answer to the question? string connectionString = "server=YourServer; uid=sa; pwd=YourPassword;...
3
by: Fernando | last post by:
I am having problems with updating the changes done over a DataSet to a Database. All the changes being done using the Form are stored in the Dataset, but when i decide to close the Form and open...
10
by: Victor | last post by:
Hello there, I have a module in VB.NET (ASP.NET) and on top I declare the SqlConnection and the SqlDataAdapter. Like: Module AccessDB Dim sqlCmd As New SqlCommand Dim conAanvraag As New
7
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise...
1
by: Ranny | last post by:
Question: What is the process to Insert a record using Dataset and SQLDataAdapter? Explanation: Thanks to Cor I am able to get a record to load, modify it, and save it to the database. My...
1
by: archana | last post by:
hi all I have some doubts related to database handling in .net. I am using sqldataadapter to update and insert rows into database. What i want to know is at a time of inserting rows using...
1
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The...
1
by: kempshall | last post by:
When I use an SqlDataAdapter to fill a DataSet from a database, do I need to explicitly open and close the SqlConnection that I'm using? For example, I have code that looks like this: ...
0
by: dakvanslam | last post by:
I apologize if this is a simple question, but I am very new to SQL Server. I feel like I am missing something easy here. I an running VB ..NET from Visual Studio 2005 and SQL Server Express. The...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.