Windows Develop Bookmark and Share   
 index > Windows Forms Designer > WinForms designer throws Exception when adding fillToolStrip component from DataSet without TableAdapters
 

WinForms designer throws Exception when adding fillToolStrip component from DataSet without TableAdapters

If you drag a dataSource(a table from a dataSet) onto a form in the WinForms designer, visual studio automatically inserts the typed dataSet, a bindingSource, a tableAdapter, tableAdapterManager and a bindingNavigator.
If there are parameters in the fill query of the table, visual studio also adds a fillToolStrip component.
Is it possible to prevent visual studio from adding the fillToolStrip? The problem ist that when this component is created, a error message occurs (An error occurred while performing the drop. Object reference not set to an instance of an object.) due to a non-standard-Dataset code generator (there is no TableAdapter name space and there were no TableAdapters generated). Afterwards, sometimes either the strip is there and no grid (showing the data table data), or no components at all. This is why we do not want the automatic generation of the strip control.

When we use our DataSetGenerator (No TableAdapters are generated), and drag a table from the dataSource onto a form, the designer works fine, it realise that there were no TableAdapters in the DataSet, so it doesnt insert the tableAdapter and the tableAdapterManager without an error. But when it try to insert the fillToolStrip, an error occurs and the disigner performs a rollback(removes the grid, DataSet , bindingSource and bindingNavigator).

Is there a way to catch the exception or even prevent the designer from performing the rollback?


Fanski  Wednesday, April 15, 2009 6:44 AM
no ideas ?
Fanski  Friday, April 17, 2009 7:13 AM

Hi Fanski,

> Is it possible to prevent visual studio from adding the fillToolStrip?

I don't see we can prevent Visual Studio from adding such a fillToolStrip if the Fill method of TableAdapter associated with the DataTable has parameters.

> The problem ist that when this component is created, a error message occurs due to a non-standard-Dataset code generator.

There isn't any problem on my side when I drag a DataTable whose associated TableAdapter's Fill method has parameters onto a form. There isn't any problem when I run the application either.

Could you please explain more about your problem?

Thanks,
Linda Liu

Linda Liu  Friday, April 17, 2009 9:50 AM

Hi Linda,

we use our own DataSetGenerator. This DataSetGenerator doesn’t generate TableAdapters.

To see the Error, please create a DataSet. Insert a parameter into the Query. Save.

Go to the generated code of the DataSet (DataSet1.Designer.cs) and remove all the code inside the second namespace (TableAdapter namespace).

On the DataSources window you see your DataSet. Drag the Table from the DataSet onto an empty Form, and you will receive the error message. There is no problem with that DataSet (without TableAdapters) as long as you don’t have Parameters in your query, and the FormDesigner doesn’t try to insert the fillToolStrip.

Best regatds,

Peter Stefanski



Fanski  Friday, April 17, 2009 2:16 PM

Hi Peter,

>To see the Error, please create a DataSet. Insert a parameter into the Query.

Do you mean add a query to the DataSet and insert a parameter into the query? Since the query is not relevant to the DataTable in the same DataSet, I don't see there will be any difference whether the query has parameters or not.

> Go to the generated code of the DataSet (DataSet1.Designer.cs) and remove all the code inside the second namespace (TableAdapter namespace).

Why do you do like that? The code in the .designer file is managed by the designer. Even if you make some changes in this file, the changes will belost when the DataSet is opened the next time.

> On the DataSources window you see your DataSet... and you will receive the error message.

I perform a test on this but don't get any error.

Thanks,
Linda Liu

Linda Liu  Monday, April 20, 2009 5:38 AM
Hallo Linda,


> Do you mean add a query to the DataSet and insert a parameter into the query? Since the query is not relevant to the DataTable in the same DataSet, I don't see there will be any difference whether the query has parameters or not.

to see the error, you need a DataSet with a DataTable which have a query with some paramater.

>Why do you do like that? The code in the .designer file is managed by the designer. Even if you make some changes in this file, the changes will belost when the DataSet is opened the next time.

How I wrote before, we use our own DataSetGenerator (custom Tool property of the dataset is set to our own DataSetGenerator, not the MSDatasetGenerator).
This generator doesn’t create TableAdapters.
If we don’t have any parameters in the Query, there is no problem with the Form designer. We can drag Tables from the DataSource to the Form, and the designer adds a grid, BindingSource and a BindingNavigator to the form without any errors. The designer even realize that there are no TableAdapters in the DataSet and doesn't insert the TableAdapter and TableAdapterManager to the Form.
But if there are Parameters in a Query of the Table you want to drag form the dataSource to the Form, the form designer also tries to insert a fillToolStrip which causes an error because this component tries to use a TableAdapter without checking if there is one.

Please try it out step by step like i wrote in the post before, so you can see what I mean.

Best regards

Peter Stefanski

Fanski  Monday, April 20, 2009 7:23 AM

Hi Peter,

Thank you for your quick response and detailed explanation!

But could you tell me how you add a query to a DataTable? I don't see I can do this in the standard MSDataSetGenerator. If this needs your custom DataSetGenerator, please send it to me for test.

I look forward to your reply.

Sincerely,
Linda Liu

Linda Liu  Tuesday, April 21, 2009 3:31 AM
Hi Linda,

I generate a DataSet with the option Data-> add New Data Source�(I select some tables from a MSSQL 2005 database)

With the DataSet designer I use the option configure on a table. (The TableAdapter configure wizard starts). There I add a parameter to the Query.

The DataSet designer still has the TableAdapters. We don’t change anything there. Just the Code that will be generated afterwards is different (DataSet1.Designer.cs).

I could send you a VS2008 project with the DataSet generated by our DataSetGenerator.

How can I send you a file?

Best Regards

Peter Stefanski

Fanski  Tuesday, April 21, 2009 9:36 AM

Hi Peter,

Thank you for your reply!

You have mentioned your custom DataSetGenerator doesn't create TableAdapters. But if there's no TableAdapters, where will the query exist?

Please create a simple project that can reproduce the problem andsend the zip fileto my email box v-lliu@microsoft.com.

Sincerely,
Linda Liu

Linda Liu  Wednesday, April 22, 2009 3:08 AM

Hi Peter,

Thank you for your sample!

I perform a test based on your description and do see the problem on my side.

Since there’s no TableAdapter for the DataTable in the DataSet defined in the dataset.designer.cs file, why not delete the TableAdapters in the DataSet designer?

Sincerely,
Linda Liu

Linda Liu  Thursday, April 23, 2009 6:59 AM
Hi Linda,

If we would delete the TableAdapters, we won’t have any Queries. The command collections are still in the DataSet (we moved them to a different place in the DataSet. You can find it in the sample). We need the Queries.

Is there a way to catch the exception or to stop the rollback (VS adds all components to the form, but after the Exception, VS removes all added components)?

Best Regards

Peter Stefanski

Fanski  Thursday, April 23, 2009 7:14 AM

You can use google to search for other answers

Custom Search

More Threads

• Need more resource for digital camera
• Add columns to usercontrol containing grid
• Multiline inputbox in propertygrid
• Using local HTML Page for help
• Using multiple resource files
• Expandable columns in DataGridView
• Adding Dataset to component tray
• TabControl behaving strangly
• Opening a form in .NET 2005
• Word automation