Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Binding DataView to custom SQL Query from TableAdapter
 

Binding DataView to custom SQL Query from TableAdapter

Still trying to learn how to get access to a custom query data in Designer.

If I use a Dataset build straight from my DB, using a DataGridView, I can set the DataSource to the Dataset, and then DataMember to a specific Table, and the DataGridView will show the data from the table.

Now if on the TableAdapter associated with the Table I add a Query, which returns a selection of the columns of the Table for example (not all columns), how do I access this from Designer?

I see I can create a QueryTableAdapter, and I can Drag it as a DataGridView on the Form, the DataSource is set to queriesTableAdapterBindingSource but no data shows... however I didn't call the Query, so I'm not sureprised, but in code I don't seem to have access to that QueryTableAdapter to call the query.

This is just confusing to me...
any insight?

Thanks for help.



  • Moved byBob BeaucheminMVPSaturday, September 19, 2009 12:38 AMMoved to a more appropriate group (From:.NET Framework inside SQL Server)
  •  
WiizzZZZ  Friday, September 18, 2009 9:25 PM
I resorted to creating a new TableAdapter, adding my query to it, and it created a new DataTable, which then I used to bind to the DataGridView (DataSource = myDataSet, DataMember = the new Table)

Filled the Table with the Query in the Form_Load as for a regular DataTable

The only annoying thing is that if I change my query, the table changes, and the Designer resets DataSource tothe TableAdapterBindingSource, which I still don't know how to force to fill the Table with my query data...


there must be a way... I guess I'm on the right track, but I still have to find out how to use the BindingSOurce properly here.
WiizzZZZ  Friday, September 18, 2009 11:25 PM

Hi WiizzZZZ,

Based on my understanding, you want to custom the table adapter. You modify some code in the designer file of the DataSet, but when the table structure changes in the database, the code in designer file is regenerated and what you modified is lost. Is that right?

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 21, 2009 9:46 AM
Sorry I didn' follow up here...

In fact I made the mistake of taking the Table from the DataSet as the DataSource, when the right thing to do is to use the BindingSource to the TableAdapter.

The Designer actually takes the BindingSource as the default (which is the right thing to do) but when changing the query, the BindingSOurce needs to be regenerated. I guess when the project is Rebuilt, that happens, but running Debugger it didn't do it right.
Removing the BindignSOurce from Designer and then picking the Table for DataSource in Designer, regenerates the BindingSource and all goes well.
WiizzZZZ  Monday, September 21, 2009 4:55 PM

Hi WiizzZZZ,

I agree what you said about regenerating code. Could you please explain your needs or the issue a little more?

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Tuesday, September 22, 2009 2:39 AM

You can use google to search for other answers

Custom Search

More Threads

• VB.net window controls for databinding
• Error: The data source does not support server-side data paging.
• Using larger font causes DataGridView edit box to clip bottom of characters
• Adding type safe columns by using Type safe derived dataset
• DataGridView: Disable arrow keys for navigation
• All I need code example to access DataTable in a dataset. Plz help
• Concurrency violation the update command affected 0 of the expected 1 records
• Solution to wrongly selected new row problem
• Typed DataSet
• Datagridview Exception: column does not allow null