Home All Groups Group Topic Archive Search About

select query changing bound controls data

Author
28 Feb 2006 5:01 PM
phonl
I am a vb6 ADO developer looking at vb.net 2005 and ADO2.net.

I used the vb.net 2005 data wizard to bind some controls to a database. Now
I want to run a select query and have the bound controls reflect the change
from the query. How would I do that?

The wizard created a TableAdapter, BindingSource, and DataSet. Somehow I
need to run feed them a select query to update the data.

Author
28 Feb 2006 5:29 PM
Larry Lard
phonl wrote:
> I am a vb6 ADO developer looking at vb.net 2005 and ADO2.net.
>
> I used the vb.net 2005 data wizard to bind some controls to a database. Now
> I want to run a select query and have the bound controls reflect the change
> from the query. How would I do that?
>
> The wizard created a TableAdapter, BindingSource, and DataSet. Somehow I
> need to run feed them a select query to update the data.

In the dataset designer, rightclick the tableadapter, choose Add |
Query... and follow through the wizard. When asked to supply the query
text, you can use parameters (eg in a access db, "select blah from
orders where id=?)". This will create a new method on the TableAdapter
called... well, called what you like, but I typically name mine
FillBy<parameter name>, eg FillByOrderDate. This method will take the
parameter as an argument. Then to run the query just do
MyTableAdapter.FillByWhatever(whatever) - this will run the query and
your bound controls will reflect the new resultset.

--
Larry Lard
Replies to group please
Author
28 Feb 2006 6:01 PM
phonl
Yup, that works!  Thank you.

Let me ask you to take it one step further...

Let say, I can't make a query in advance because I don't know what it is at
design time; so I put an unbound text box on the form for typing in a select
statement and I want to execute the select statement against the bound
controls.  How would I do that?


Show quoteHide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1141147790.085513.44280@u72g2000cwu.googlegroups.com...
>
> phonl wrote:
>> I am a vb6 ADO developer looking at vb.net 2005 and ADO2.net.
>>
>> I used the vb.net 2005 data wizard to bind some controls to a database.
>> Now
>> I want to run a select query and have the bound controls reflect the
>> change
>> from the query. How would I do that?
>>
>> The wizard created a TableAdapter, BindingSource, and DataSet. Somehow I
>> need to run feed them a select query to update the data.
>
> In the dataset designer, rightclick the tableadapter, choose Add |
> Query... and follow through the wizard. When asked to supply the query
> text, you can use parameters (eg in a access db, "select blah from
> orders where id=?)". This will create a new method on the TableAdapter
> called... well, called what you like, but I typically name mine
> FillBy<parameter name>, eg FillByOrderDate. This method will take the
> parameter as an argument. Then to run the query just do
> MyTableAdapter.FillByWhatever(whatever) - this will run the query and
> your bound controls will reflect the new resultset.
>
> --
> Larry Lard
> Replies to group please
>
Author
1 Mar 2006 6:00 AM
Peter Huang" [MSFT]
Hi Phonl,

If you need to define the Select in the runtime, we need to create the Data
Access code ourself.
Here is a link about how to do DataBinding at runtime, you may have a try.
See Binding to Controls Programmatically
http://www.developer.com/net/vb/article.php/3558771

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.