Data Access in Client and Middle-Tier Programming
Dataset Designer

The Dataset Designer is a set of visual tools for creating and editing typed datasets and the individual items that make up datasets.

The Dataset Designer provides visual representations of the objects contained in typed datasets. You create and modify TableAdapters, TableAdapter Queries, DataTables, DataColumns, and DataRelations with the Dataset Designer.

To open the Dataset Designer, double-click a dataset in Solution Explorer, or right-click a dataset in the Data Sources window and click Edit DataSet with Designer. For more information, see How to: Open a Dataset in the Dataset Designer. Adding a new DataSet item with the Add New Item dialog box will open the Dataset Designer with an empty dataset ready for editing.

NoteNote:

The Dataset Designer can be used to extend the functionality of a dataset. Double-click the design surface or right-click and choose View Code to create a partial class file where you can add code to the dataset that will not be changed or deleted by the designer. For information on extending the functionality of a TableAdapter, see How to: Extend the Functionality of a TableAdapter.

The following table lists the common tasks you can accomplish with the Dataset Designer.

To

See

Create a TableAdapter

How to: Create TableAdapters

Edit a TableAdapter

How to: Edit TableAdapters

Create a TableAdapter query

How to: Create TableAdapter Queries

Edit a TableAdapter query

How to: Edit TableAdapter Queries

Create a DataTable

How to: Create DataTables

Edit a DataTable

Designing DataTables

Create a DataColumn

How to: Add Columns to a DataTable

Create a relationship between two DataTables

How to: Create DataRelations with the Dataset Designer

Extend the functionality of the dataset

How to: Extend the Functionality of a Dataset

Add validation to a data table's ColumnChanging event

How to: Validate Data During Column Changes

Add validation to a data table's RowChanging event

How to: Validate Data During Row Changes

Creating Objects on the Design Surface

You can create datasets by adding and editing the individual objects that make up a dataset. The following table provides an explanation of the different objects in the DataSet tab on the Toolbox that can be dragged onto the design surface:

Object

Description

TableAdapter

Contains a collection of data commands and a data connection that are used to communicate with the underlying database and populate a data table. For more information, see TableAdapter Overview and How to: Create TableAdapters.

Query

TableAdapter queries are strongly typed methods that execute SQL statements and stored procedures. Running a TableAdapter query populates a data table with data or performs other database tasks. For more information, see How to: Create TableAdapter Queries. Dragging a query onto a table adds the query to that table, whereas dragging a query onto an empty area of the Dataset Designer creates a global query. For more information, see How to: Add Global Queries to a Dataset.

DataTable

Represents an in-memory collection of the rows returned from a database.

Relation (DataRelation)

Represents a parent-child relationship between two DataTables. For more information, see Introduction to DataRelation Objects and Walkthrough: Creating a Relationship between Data Tables.

LINQ to Dataset

LINQ to DataSet enables Language-Integrated Query (LINQ) over data in a DataSet object. For more information, see LINQ to DataSet.

See Also

Tasks

Concepts

Reference

Other Resources

Tags :


Community Content

Willip_Ltd
Dataset Designer
I do not have dataset designer as part of any menu in Visual Studio. Where do I get it


18 Feb 2009: Me too! Spent 2 days on this reading lots of old threads. Very frustrated! Installed VS2008 SP1. Then ran “devenv /resetsettings” AND then “devenv /setup” in Visual Studio Tools-> Visual Studio 2008 Command Prompt. Loaded up a project. Right clicked .xsd file, then "Open With", selected DataSet Editor. It worked!

Alastair Bell
Error: RowGuids / Default value: 'System.Guid' cannot be converted to type 'System.String'

This note is included to address the incorrect behavior of the Dataset Designer that can cause new inserts to fail in the datagridview or when attempting to correct the issue within the designer in the way that makes sense, you get the following error from the dataset designer upon a save

Custom tool error: Failed to generate code. Failed to generate code. Object of type 'System.Guid' cannot be converted to type 'System.String'. Object of type 'System.Guid' cannot be converted to type 'System.String'

Here is the scenario, A table is defined that has a UniqueIdentifier row, defined as the table's RowGuid and set as the primary key, and the New Value is set to "NewId()" in the table definition; thus upon insert a new guid will be generated and assigned to the table.

You create a new DataSet, drag the table onto the designer. The RowGuid is included in the resulting dataset. Since it is the primary key the dataset marks it as Null not allowed, raise an error during validation if Null and finally the default value will be set to <DBNull>.

Now you don't want to show the Guid to the end users, because they don't want to know about them and you especially don't want to require them to have to enter a new one. On a form you place a DataGridView, and you bind it to your dataset, and you allow insert from the grid, and you remove the Guid column, knowning the database will create one for you upon insert.

When you try to add a row thru the DataGridView, however you will get an error on insert due to the fact the Guid is NULL and that is invalid. So the next thing you try is to allow nulls in the Dataset Designer, that will fail. The next thing to try is specify a default value for the Guid in the designer. This is where you get the error. If you attempt to add a string "00000000-0000-0000-0000-000000000000" for example you will get an error setting that property that the value is of the incorrect type. If you then attempt to add the value without the quotes -- 00000000-0000-0000-0000-000000000000 -- the designer accepts the value, and then when you try to save your changes the error list in VS tells you that:

Error 33 Custom tool error: Failed to generate code. Failed to generate code. Object of type 'System.Guid' cannot be converted to type 'System.String'. Object of type 'System.Guid' cannot be converted to type 'System.String'. C:\Users\<username>\Documents\Visual Studio 2008\Projects\databinding\DataBindingWinForm\DVDListDataSet.xsd 1 1

OK, so you can't leave it null, you can't set the default value to a string representation, and you can't set the default value to a literal representation... What do you do? Making the guid visible and making you user specify one doesn't seem like a good idea to me.

You can address the problem by adding code to the TableNewRow event of the dataset's table.

in the Form1_Load event add a new handler, to that event and then in the event, set the Guid's value like this


private void Form1_Load ( object sender , EventArgs e )
{
// TODO: This line of code loads data into the 'dVDListDataSet.DVDs' table. You can move, or remove it, as needed.
this.dVDsTableAdapter.Fill( this.dVDListDataSet.DVDs );
this.dVDListDataSet.DVDs.TableNewRow += new DataTableNewRowEventHandler( DVDs_TableNewRow );
}
void DVDs_TableNewRow ( object sender , DataTableNewRowEventArgs e )
{
e.Row.SetField<Guid>( "Uid" , Guid.NewGuid( ) );
}


Another way of achieving the above would be to add a partial class to the dataset.
For example :-

  

Partial Class MyDatabaseDataSet

Partial Class jobsDataTable

Private Sub newJobsDataTableRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs) Handles MyClass.TableNewRow

e.Row.SetField(rowguidColumn, Guid.NewGuid)

End Sub

End Class

End Class


This has the advantage of setting the value for the guid column wherever it is used rather than just in the form where the event handler is added.


 
  


Tags : guid rowguids

Page view tracker