designing datatables

Upload: fatty2000000

Post on 04-Jun-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Designing DataTables

    1/19

    Designing DataTablesVisual Studio 2012

    Other Versions

    This topic has not yet been rated - Rate this topic

    Visual Studio provides design-time tools for creating and editing data tables (DataTable). For an

    overvie of hat a DataTableis! see"ataTables (#"O.$%T).

    The folloing topics e&plain ho to create data tables! add them to typed datasets using the

    "ataset "esigner! and create and edit the data columns (DataColumn) that define them.

    Note

    The dialog bo&es and menu commands you see might differ from those described in 'elpdepending on your active settings or edition. To change your settings! choose mport and %&port

    Settings on the Tools menu. For more information! see Visual Studio Settings.

    n This Section

    'o to *reate "ata Tables

    +rovides the steps to create a ne "ataTableith the "ataset "esigner.

    'o to #dd *olumns to a "ataTable

    +rovides the steps to create a ne "ata*olumnin an e&isting "ataTable.

    ,althrough *reating a "ataTable in the "ataset "esigner

    +rovides step-by-step instructions for creating a"ataTableand defining the

    "ata*olumns that mae up its structure.

    Reference"ataSet

    Represents an in-memory cache of data.

    "ataTable

    Represents one table of in-memory data.

    "ata*olumn

    Represents the schema of a column in a "ataTable.

    http://msdn.microsoft.com/en-us/library/vstudio/ms171909(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/ms171909(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171909(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    2/19

    "ataRelation

    Represents a parentchild relationship beteen to "ataTableob/ects.

    Related Sections

    "ataTables (#"O.$%T)

    "escribes ho to create and customi0e "ataTable ob/ects.

    Table#dapters

    +rovides lins to topics that e&plain ho to create and edit Table#dapters ith design

    time tools.

    *onnecting to "ata in Visual Studio

    +rovides lins to topics that e&plain the different ays to connect to data in VisualStudio.

    +reparing 1our #pplication to Receive "ata

    +rovides lins to topics e&plaining hat datasets are! ho to create ne datasets! and

    ho to create and edit the individual ob/ects they are made of.

    Fetching "ata into 1our #pplication

    +rovides lins to topics e&plaining ho to e&ecute 2ueries and stored procedures! and

    load data into datasets.

    3inding *ontrols to "ata in Visual Studio

    +rovides lins to topics that e&plain ho to display data on ,indos Forms through

    databound controls.

    %diting "ata in 1our #pplication

    +rovides lins to topics that e&plain oring ith the data in a dataset.

    Validating "ata

    +rovides lins to topics e&plaining here to put code to validate data.

    Saving "ata

    +rovides lins to topics e&plaining ho to send updated data from an application to the

    database.

    http://msdn.microsoft.com/en-us/library/vstudio/system.data.datarelation(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarelation(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7zt3ycf2(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171886(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171886(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171895(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171918(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171923(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171928(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t3b36awf(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t3b36awf(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171932(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarelation(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7zt3ycf2(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171886(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171895(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171918(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171923(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171928(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t3b36awf(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171932(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    3/19

    How to: Create DataTables

    Visual Studio 2012

    Other Versions

    2 out of 3 rated this helpful - Rate this topic

    "ata can be stored in memory in"ataTableob/ects. ("atasets are made up of "ataTable

    ob/ects.) 1ou typically create ne data tables ith Table#dapters using the Table#dapter*onfiguration ,i0ardor by dragging database ob/ects from Server %&plorer onto the "ataset

    "esigner.

    "ata tables are created as a byproduct hen you create ne Table#dapters in the "ata Source

    *onfiguration ,i0ardas ell! but they can also be created independently. 1ou create astandalone data table by dragging a"ataTableob/ect from the "ataSet tab of the Toolbo& onto

    the "ataset "esigner.

    Note

    To create data tables programmatically! see *reating a "ataTable (#"O.$%T).

    Note

    1our computer might sho different names or locations for some of the Visual Studio user

    interface elements in the folloing instructions. The Visual Studio edition that you have and thesettings that you use determine these elements. For more information! see Visual Studio Settings.Creating a DataTable with TableAdapter

    "ata tables ith Table#dapters include methods that fill the table ith data and rite changes

    bac to the database. 1ou create Table#dapters by running the Table#dapter *onfiguration,i0ard or by dragging database ob/ects from Server %&plorer onto the "ataset "esigner.

    To create a new data table with TableAdapter

    4. Open your dataset in the "ataset "esigner. For information! see 'o to Open a "ataset

    in the "ataset "esigner.

    5. "rag a Table#dapter from the "ataSet tab of the Toolbo& onto the "ataset "esigner.

    The Table#dapter *onfiguration ,i0ard opens.

    http://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w4dd7z6t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w4dd7z6t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w4dd7z6t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w4dd7z6t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    4/19

    6. *omplete the i0ard. For more information! see Table#dapter *onfiguration ,i0ard

    To create a new data table with a TableAdapter from Server Explorer

    4. Open your dataset in the "ata Source "esigner.

    5. "rag a database ob/ect (for e&ample! a table) from Server %&plorer onto the "ataset"esigner.

    Creating a Standalone DataTable

    Standalone tables need to have Fill logic implemented in order to be filled ith data. For

    information on filling standalone data tables! see+opulating a "ataSet from a "ata#dapter

    (#"O.$%T).

    To create a new stand alone data table

    4. Open your dataset in the "ataset "esigner.5. "rag a "ataTablefrom the "ataSet tab of the Toolbo& onto the "ataset "esigner.

    6. #dd columns to define your data table. For more information! see 'o to #dd *olumns

    to a "ataTable.

    See Also

    How to: Add Columns to a DataTable

    Visual Studio 2012

    Other Versions

    1 out of 1 rated this helpful - Rate this topic

    1ou create the individual columns ("ata*olumn) that mae up data tables ("ataTable) byadding them to the "ata*olumn*ollectionfor a data table. 1ou can add columns to data tables

    visually ith the "ataset "esigner! or ith one of the data i0ards. For more information aboutho to add data columns to data tables programmatically! see #dding *olumns to a "ataTable(#"O.$%T).

    #fter you add the columns! you can configure them to meet your re2uirements. For e&ample! you

    can specify a default value! or a uni2ueness constraint for a column. 1ou can also specify that a

    column should display a calculated value! instead of a value read directly from the database.

    http://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumncollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/dex7k4dw(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumncollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    5/19

    Note

    The dialog bo&es and menu commands you see might differ from those described in 'elp

    depending on your active settings or edition. To change your settings! choose mport and %&portSettings on the Tools menu. For more information! see Visual Studio Settings.Coon Tas!s

    Task Supporting Content

    #dd columns to tables 1ou can add columns by using the "ataset"esigner! the "ata Source *onfiguration ,i0ard! or the

    Table#dapter *onfiguration ,i0ard.

    #dding *olumns to a

    "ata Table

    *onfigure "ata*olumns *olumns are added ith default

    properties. 1ou can customi0e settings for each "ata*olumn tospecify its behavior. For e&ample! you can specify the data type! a

    default value! or constraint a column to contain uni2ue values. n

    addition! you can configure a data column to display a calculatedvalue instead of a value that is read directly from the database.

    *onfiguring

    "ata*olumns

    *onfigure a

    "ata*olumn to

    "isplay an %&pression

    Adding Coluns to a Data Table

    3efore you can configure a "ata*olumn! you must first add it to a "ataTable. 1ou can do so by

    using any of the folloing procedures.

    To add a column to a DataTable with the Dataset Designer

    4. Open your dataset in the "ataset "esigner. For more information! see 'o to Open a"ataset in the "ataset "esigner.

    5. Right-clic the "ataTable to add the column. +oint to #dd! and then clic *olumn.

    6. Replace the default column name! if desired! by selecting the column name in the data

    table and editing the te&t.

    7. Set the "ataTypeproperty in the +roperties indo.

    To add a column to a DataTable with the Data Source Configuration Wizard

    4. n the "ata Sources indo! right-clic the data source! and then clic *onfigure

    "ataSet ith ,i0ard.

    5. %&pand the table you ant to add a column to.

    6. Select the columns to add to the table.

    7. *lic Finish.

    http://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#addcolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#addcolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#configuringdatacolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#configuringdatacolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zbhkx167(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#addcolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#addcolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#configuringdatacolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#configuringdatacolumnshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#creatingdatacolumnsdisplayexpressionshttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    6/19

    To add a column to a DataTable with the TableAdapter Configuration Wizard

    4. Open your dataset in the "ataset "esigner. For more information! see 'o to Open a

    "ataset in the "ataset "esigner.

    5. Right-clic the data table! and then clic *onfigure.

    6. #dd the column to the S%8%*T statement.

    7. *lic Finish.

    Configuring DataColuns

    #fter you add a "ata*olumn! you specify the behavior of that "ata*olumn. For e&ample! you

    might ant to change the data type or restrict it to only contain uni2ue values. 1ou can use any

    of the folloing procedures to modify "ata*olumn behavior.

    Setting the "ata Type of a "ata*olumn Specifying the *aption of a "ata*olumn

    Specifying that a "ata*olumn *ontain #uto-9enerated $umbers

    #ssigning a "efault Value to a "ata*olumn

    *onstraining a "ata*olumn to *ontain :ni2ue Values

    Setting a "ata*olumn to be the +rimary ;ey in a "ataTable

    Specifying the Return Value hen the Value of a "ata*olumn is $ull

    Setting the Data T"pe of a DataColun

    "ata columns ("ata*olumn) are created ith a default data type ofString. To change the data

    type of a column! set the "ataTypeproperty in the +roperties indo.

    To set the data type of a DataColumn

    4. Open a dataset in the "ataset "esigner.

    5. Select the column you ant to set the data type for.

    6. n the +roperties indo! select the desired data type from the "ataTypelist.

    Specif"ing the Caption of a DataColun

    "ata columns often have names that are not suited for displaying in a user interface. 1ou can

    change the caption to a more suitable name by setting the *aptionproperty in the +ropertiesindo.

    http://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#setdatatypehttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifycaptionhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifyautogeneratednumbershttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#assigndefaultvaluehttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifyuniqueconstrainthttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#setprimarykeyhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#handlenullvalueshttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.caption(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.caption(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#setdatatypehttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifycaptionhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifyautogeneratednumbershttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#assigndefaultvaluehttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#specifyuniqueconstrainthttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#setprimarykeyhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspx#handlenullvalueshttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.datatype(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.caption(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    7/19

    Note

    # special consideration comes into play hen you drag items from the "ata Sources indo

    onto a form in a ,indos application the column names in the caption labels are reformattedinto a more readable string hen to or more ords are found to be concatenated together. For

    more information! see 'o to *ustomi0e 'o Visual Studio *reates *aptions for "ata-bound

    *ontrols.

    To edit the caption of a data column

    4. Open your dataset in the "ataset "esigner. For more information! see 'o to Open a

    "ataset in the "ataset "esigner.5. Select the column hose caption you ant to edit.

    6. n the +roperties indo! set the *aptionproperty.

    Specif"ing that a DataColun Contain Auto-#enerated $ubers

    "ata columns ("ata*olumn) often contain auto-generated se2uential numbers< for e&ample!

    primary eys and " columns. 1ou can load auto-generated numbers in data columns by settingthe #utoncrement!#utoncrementSeed!and#utoncrementStepproperties of the data column.

    ,hen data columns are created by means of Visual Studio design tools! the columns are

    automatically mared as #utoncrement. ,hen you update a table in the database that contains

    an dentity column! the values created ith the auto-numbering feature are not sent to thedatabase.

    To set a data column to contain autogenerated numbers

    4. Open your dataset in the "ataset "esigner.

    5. Select the column you ant to populate ith auto-generated numbers.

    6. n the +roperties indo! set the folloing properties

    Propert Setting

    #utoncrement true

    #utoncrementSeedf you ant to begin at a number different from the default value of

    =! set this value to the starting number for this column.

    #utoncrementStep n each ne ro! the column value is incremented by this value.

    Note

    http://msdn.microsoft.com/en-us/library/vstudio/ms233769(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms233769(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.caption(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementseed(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementseed(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementstep(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementstep(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementseed(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementstep(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms233769(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms233769(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.caption(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementseed(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementstep(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrement(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementseed(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.autoincrementstep(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    8/19

    Setting a data column to auto-increment does not automatically designate the column as a

    primary ey.Assigning a Default Value to a DataColun

    "ata columns can be assigned default values. The default value is assigned in the column as neros (records) are created.

    To assign a default value to a data column

    4. Open a dataset in the "ataset "esigner.

    5. Select the column you ant to assign a default value to.

    6. n the +roperties indo! set the "efaultValueproperty to the desired default value.

    Constraining a DataColun to Contain %ni&ue Values

    1ou set a "ata*olumnto contain uni2ue values by adding a uni2ue constraint to a data table.

    :ni2ue constraints are also called eys. >aring a column as a +rimary ;ey in the "atasetdesigner ill create a :ni2ue *onstraint

    To constrain a column to contain uni!ue values

    4. Open your dataset in the "ataset "esigner.

    5. Right-clic the column you ant to constrain to uni2ue values. +oint to #dd! and then

    clic ;ey.

    6. Verify that the correct column is selected in the :ni2ue *onstraint dialog bo&.

    7. Replace the default name of the constraint ith a more meaningful name! if desired.

    Setting a DataColun to be the 'riar" (e" in a DataTable

    Setting a data column as the primary ey guarantees that each record contains a uni2ue value.

    Only one primary ey can be assigned to a data table. 1ou create a primary ey in a data table

    using the "ataset "esigner.

    To set a data column to be the primary "ey in a data table

    4. Open your dataset in the "ataset "esigner.

    5. Right-clic the column you ant to set as the primary ey. *lic Set +rimary ;ey.

    # ey icon appears ne&t to the selected column(s).

    Specif"ing the Return Value when the Value of a DataColun is $ull

    http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.defaultvalue(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://void%280%29/http://void%280%29/http://void%280%29/http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.defaultvalue(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://void%280%29/http://void%280%29/
  • 8/13/2019 Designing DataTables

    9/19

    n a typed dataset! you can control the representation of columns that contain null values. This

    behavior is only available hen retrieving column values through their typed accessors. f you

    retrieve the value by means of the table?s ro inde& or column inde&! you ill not be able to setthe return value. The reason for this is that the logic to return this value is built into the property

    setter of the specific data column in the generated dataset class.

    To set the value to return when a DataColumn#s value is null

    4. Open the dataset in the "ataset "esigner.

    5. Select a column in a data table.

    6. n the +roperties indo! select the $ullValue property.

    7. "o one of the folloing

    o From the drop-don list! select the appropriate value

    Value Des!ription

    (%mpty) Returns null valuesString.%mpty.

    ($othing) Returns null values as"3$ull.

    (Thro e&ception) $ull values thro an %&ception.

    o -or-

    o Set the property to any custom value valid for that column?s data type. Fore&ample! if you specify the string $o Value! for a column ith a data type of

    String! any records that contain null values in that column ill display @$oValue@.

    Configure a DataColun to Displa" an )*pression

    # data table in a dataset can contain columns in hich the value is calculated rather than read

    from the database. For e&ample! in an order details record! it might mae sense to define an

    %&tended+rice column by multiplying the 2uantity times the price! rather than actually storingthe total in the record. *alculated columns can also add or count values in child records and filter

    other records. 1ou can define calculated columns using e&pressions.

    The synta& of the e&pression consists of standard operators. 1ou can reference a data value using

    its column name (as you ould in an SA8 statement) and include aggregate functions such as*ount.

    For e&ample! the e&pression for an %&tended+rice column based on the :nit+rice times Auantity

    columns of the current record might simply be

    http://msdn.microsoft.com/en-us/library/vstudio/system.string.empty(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string.empty(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.dbnull(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.dbnull(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.exception(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/system.string.empty(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.dbnull(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.exception(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.string(v=vs.110).aspxhttp://void%280%29/
  • 8/13/2019 Designing DataTables

    10/19

    :nit+rice B Auantity

    To refer to columns in child tables! you can use the reserved ord *hild! folloed by the name

    of the column. For e&ample! the folloing e&pression returns the average value of the +ricecolumn in all related child records

    #vg(*hild.+rice)

    For more information! see the %&pressionproperty.

    1ou can create e&pression columns in the "ataset "esigner.For more information about creating

    columns! see 'o to #dd *olumns to a "ataTable.

    To create column expressions in the Dataset Designer

    4. Open your dataset in the "ataset "esigner. For more information! see 'o to Open a

    "ataset in the "ataset "esigner.5. n the data table that you ant! select the column you ant to add the e&pression to! or

    add a ne column to the table. For more information! see 'o to #dd *olumns to a"ataTable.

    6. n the +roperties indo! enter an e&pression in the%&pressionproperty.

    Related Topics

    Categor Topi!

    Overvie information 8earn more about

    ho to or ith data in Visual Studio.

    3inding *ontrols to "ata in Visual Studio

    *onnecting to "ata in Visual Studio

    "ata Sources Overvie

    *reating and %diting Typed "atasets

    "esigning "ataTables

    %diting "ata in 1our #pplication

    Fetching "ata into 1our #pplication

    +reparing 1our #pplication to Receive "ata

    Saving "ata

    http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/314t4see(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/314t4see(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/ms171923(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171886(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/8s2t4x15(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/314t4see(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171909(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171928(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171918(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171895(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171932(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/314t4see(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7973zb70(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/0c5wf85e(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/ms171923(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171886(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/8s2t4x15(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/314t4see(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171909(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171928(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171918(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171895(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171932(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    11/19

    Table#dapters

    Validating "ata

    ,hat?s $e for "ata #pplication

    "evelopment in Visual Studio 5=45

    #dditional +rocedures 8earn about other

    procedures for oring ith data.

    "ata ,althroughs

    'o to *onnect to "ata in a "atabase

    'o to *reate "ata Tables

    ,althrough "isplaying "ata on a

    ,indos Form

    ,althrough *reating a "ataTable in the

    "ataset "esigner

    Reference 8earn about classes and membersthat you use hen oring ith data.

    "ataTable

    "ata*olumn

    "ataSet

    DataTables

    "N#T $ramework %"&

    Other Versions

    = out of 5 rated this helpful - Rate this topic

    # "ataSetis made up of a collection of tables! relationships! and constraints. n #"O.$%T!"ataTableob/ects are used to represent the tables in a DataSet. # DataTablerepresents one

    table of in-memory relational data< the data is local to the .$%T-based application in hich it

    resides! but can be populated from a data source such as >icrosoft SA8 Server using a

    DataAdapterFor more information! see +opulating a "ataSet from a "ata#dapter.

    The DataTableclass is a member of the Sstem"Datanamespace ithin the .$%T Frameor

    class library. 1ou can create and use a DataTableindependently or as a member of a DataSet!

    and DataTableob/ects can also be used in con/unction ith other .$%T Frameor ob/ects!including the "ataVie. 1ou access the collection of tables in a DataSetthrough the Tables

    property of the DataSetob/ect.

    http://msdn.microsoft.com/en-us/library/vstudio/7zt3ycf2(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t3b36awf(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/87sfaezs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/87sfaezs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fxsa23t6(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fxk9yw1t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/wwh8ka92(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/wwh8ka92(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataview(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/7zt3ycf2(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t3b36awf(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/87sfaezs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/87sfaezs(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fxsa23t6(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fxk9yw1t(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/f704wwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/wwh8ka92(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/wwh8ka92(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ms171910(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/t31h6yhs(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/bh8kx08z(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataview(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    12/19

    The schema! or structure of a table is represented by columns and constraints. 1ou define the

    schema of a DataTableusing "ata*olumnob/ects as ell as Foreign;ey*onstraintand

    :ni2ue*onstraintob/ects. The columns in a table can map to columns in a data source! containcalculated values from e&pressions! automatically increment their values! or contain primary ey

    values.

    n addition to a schema! a DataTablemust also have ros to contain and order data. The

    "ataRoclass represents the actual data contained in a table. 1ou use the Data'owand itsproperties and methods to retrieve! evaluate! and manipulate the data in a table. #s you access

    and change the data ithin a ro! the Data'owob/ect maintains both its current and original

    state.

    1ou can create parent-child relationships beteen tables using one or more related columns in

    the tables. 1ou create a relationship beteen DataTableob/ects using a "ataRelation.

    Data'elationob/ects can then be used to return the related child or parent ros of a particular

    ro. For more information! see #dding "ataRelations.

    n This Section

    *reating a "ataTable

    %&plains ho to create a DataTableand add it to a DataSet.

    "ataTable Schema "efinition

    +rovides information about creating and using DataColumnob/ects and constraints.

    >anipulating "ata in a "ataTable

    %&plains ho to add! modify! and delete data in a table. %&plains ho to use DataTable

    events to e&amine changes to data in the table.

    'andling "ataTable %vents

    +rovides information about the events available for use ith a DataTable! including

    events hen column values are modified and ros are added or deleted.

    Creating a DataTable

    .NET Framework 4.5

    Other Versions

    http://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.foreignkeyconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarelation(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ay82azad(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/etk0s9w0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/etk0s9w0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/tzwewss0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w9y9a401(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w9y9a401(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.foreignkeyconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarelation(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ay82azad(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/etk0s9w0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/tzwewss0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/w9y9a401(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    13/19

    + out of , rated this helpful - Rate this topic

    # "ataTable! hich represents one table of in-memory relational data! can be created and used

    independently! or can be used by other .$%T Frameor ob/ects! most commonly as a member

    of a "ataSet.

    1ou can create a DataTableob/ect by using the appropriate DataTableconstructor. 1ou can

    add it to the DataSetby using the Addmethod to add it to the DataTableob/ect?s Tables

    collection.

    1ou can also create DataTableob/ects ithin a DataSetby using the $illor $illS!(emamethods of the DataAdapterob/ect! or from a predefined or inferred C>8 schema using the

    'ead)ml! 'ead)mlS!(ema! or *n+er)mlS!(emamethods of the DataSet. $ote that after you

    have added a DataTableas a member of the Tablescollection of one DataSet! you cannot add it

    to the collection of tables of any other DataSet.

    ,hen you first create a DataTable! it does not have a schema (that is! a structure). To define theschema of the table! you must create and add"ata*olumnob/ects to the Columnscollection of

    the table. 1ou can also define a primary ey column for the table! and create and add Constraintob/ects to the Constraintscollection of the table. #fter you have defined the schema for a

    DataTable! you can add ros of data to the table by adding Data'owob/ects to the 'ows

    collection of the table.

    1ou are not re2uired to supply a value for the Table$ameproperty hen you create a

    DataTable< you can specify the property at another time! or you can leave it empty. 'oever!

    hen you add a table ithout a TableNamevalue to a DataSet! the table ill be given an

    incremental default name of TableN! starting ith @Table@ for Table=.

    Note

    ,e recommend that you avoid the @TableN@ naming convention hen you supply a TableName

    value! because the name you supply may conflict ith an e&isting default table name in the

    DataSet. f the supplied name already e&ists! an e&ception is thron.

    The folloing e&ample creates an instance of a DataTableob/ect and assigns it the name

    @*ustomers.@

    C

    V.

    DataTable workTable = newDataTable("Customers");

    The folloing e&ample creates an instance of a DataTableby adding it to the Tablescollectionof a DataSet.

    http://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.tablename(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1http://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.tablename(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
  • 8/13/2019 Designing DataTables

    14/19

    C

    V.

    DataSet customers = newDataSet();

    DataTable customersTable = customers.Tables.Add("CustomersTable");

    See Also

    Reference

    DataTable S!(ema De+inition

    "N#T $ramework %"&

    Other Versions

    = out of 4 rated this helpful - Rate this topic

    The schema! or structure! of a table is represented by columns and constraints. 1ou define the

    schema of a "ataTableusing "ata*olumnob/ects as ell as Foreign;ey*onstraintand

    :ni2ue*onstraintob/ects. The columns in a table can map to columns in a data source! containcalculated values from e&pressions! automatically increment their values! or contain primary ey

    values.

    References by name to columns! relations! and constraints in a table are case-sensitive. To or

    more columns! relations! or constraints can therefore e&ist in a table that have the same name! butthat differ in case. For e&ample! you can have Col1and !ol1. n such as case! a reference to one

    of the columns by name must match the case of the column name e&actly< otherise an

    e&ception is thron. For e&ample! if the table mTablecontains the columns Col1and !ol1! youould reference Col1by name as mTable"Columns,-Col1-.! and !ol1as

    mTable"Columns,-!ol1-.. #ttempting to reference either of the columns as

    mTable"Columns,-C/1-.ould generate an e&ception.

    The case-sensitivity rule does not apply if only one column! relation! or constraint ith aparticular name e&ists. That is! if no other column! relation! or constraint ob/ect in the table

    matches the name of that particular column! relation! or constraint ob/ect! you may reference the

    ob/ect by name using any case! and no e&ception is thron. For e&ample! if the table has only

    Col1! you can reference it using m"Columns,-C/1-..

    Note

    The *aseSensitiveproperty of the DataTabledoes not affect this behavior. The CaseSensitie

    property applies to the data in a table and affects sorting! searching! filtering! enforcingconstraints! and so on! but not to references to the columns! relations! and constraints.

    n This Section

    #dding *olumns to a "ataTable

    http://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/etk0s9w0(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.foreignkeyconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.casesensitive(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/6zd7cwzh(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/etk0s9w0(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.foreignkeyconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.uniqueconstraint(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.casesensitive(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/hfx3s9wd(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    15/19

    "escribes ho to define the columns of a table using DataColumnob/ects.

    *reating %&pression *olumns

    %&plains ho the #pressionproperty of a column can be used to calculate values based

    on the values from other columns in the ro.

    *reating #utoncrement *olumns

    "escribes ho a column can be set to automatically increment numerical values to ensure

    a uni2ue column value per ro.

    "efining +rimary ;eys

    "escribes ho to specify the primary ey of a table from one or more DataColumnob/ects.

    "ataTable *onstraints

    "escribes ho to define foreign ey and uni2ue constraints for columns in a table.

    3anipulating Data in a DataTable

    "N#T $ramework %"&

    Other Versions

    = out of 5 rated this helpful - Rate this topic

    #fter creating a "ataTablein a "ataSet! you can perform the same activities that you ould

    hen using a table in a database. 1ou can add! vie! edit! and delete data in the table< you can

    monitor errors and events< and you can 2uery the data in the table. ,hen modifying data in a

    DataTable! you can also verify hether the changes are accurate! and determine hether to

    programmatically accept or re/ect the changes.

    n This Section

    #dding "ata to a "ataTable

    %&plains ho to create ne ros and add them to a table.

    Vieing "ata in a "ataTable

    Adding Data to a DataTable

    http://msdn.microsoft.com/en-us/library/vstudio/zwxk25bd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ksz8ess1(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ksz8ess1(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z24kefs8(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/st1t2c35(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/tzwewss0(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/zwxk25bd(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/ksz8ess1(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z24kefs8(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/st1t2c35(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/tzwewss0(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataset(v=vs.110).aspxhttp://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    16/19

    "N#T $ramework %"&

    Other Versions

    D out of E rated this helpful - Rate this topic

    #fter you create a "ataTableand define its structure using columns and constraints! you can add

    ne ros of data to the table. To add a ne ro! declare a ne variable as type "ataRo. # ne

    Data'owob/ect is returned hen you call the$eRomethod. The DataTablethen creates

    the Data'owob/ect based on the structure of the table! as defined by the"ata*olumn*ollection.

    The folloing e&ample demonstrates ho to create a ne ro by calling the New'owmethod.

    *V3DataRow workRow = workTable.NewRow();

    1ou then can manipulate the nely added ro using an inde& or the column name! as shon in

    the folloing e&ample.

    *V3workRow["CustLName" = "Sm!t";

    workRow[# = "Sm!t";

    #fter data is inserted into the ne ro! the Addmethod is used to add the ro to the"ataRo*ollection!shon in the folloing code.

    *

    V3workTable.Rows.Add(workRow);

    1ou can also call the Addmethod to add a ne ro by passing in an array of values! typed as

    Ob/ect! as shon in the folloing e&ample.

    *V3workTable.Rows.Add(new$b%ect[ ' "Sm!t");

    +assing an array of values! typed as /b4e!t! to the Addmethod creates a ne ro inside the

    table and sets its column values to the values in the ob/ect array. $ote that values in the array are

    matched se2uentially to the columns! based on the order in hich they appear in the table.

    The folloing e&ample adds 4= ros to the nely created Customerstable.

    *

    http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.newrow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumncollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumncollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2http://msdn.microsoft.com/en-us/library/vstudio/system.data.datarowcollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarowcollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3http://msdn.microsoft.com/en-us/library/vstudio/system.object(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-4http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.newrow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumncollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2http://msdn.microsoft.com/en-us/library/vstudio/system.data.datarowcollection(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3http://msdn.microsoft.com/en-us/library/vstudio/system.object(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-4
  • 8/13/2019 Designing DataTables

    17/19

    V3DataRow workRow;

    or(!nt! = *; ! += ,; !--)

    &

    workRow = workTable.NewRow();

    workRow[* = !;

    workRow[# = "CustName"- !.ToStr!n();

    workTable.Rows.Add(workRow);

    See #lso

    Viewing Data in a DataTable

    "N#T $ramework %"&

    Other Versions

    4 out of 4 rated this helpful - Rate this topic

    1ou can access the contents of a "ataTableby using the 'owsand Columnscollections of the

    DataTable. 1ou can also use the Selectmethod to return subsets of the data in a DataTableaccording to criteria including search criteria! sort order! and ro state. #dditionally! you can use

    the Findmethod of the Data'owColle!tionhen searching for a particular ro using a primary

    ey value.

    The Sele!tmethod of the DataTableob/ect returns a set of"ataRoob/ects that match the

    specified criteria. Sele!ttaes optional arguments of a filter e&pression! sort e&pression! andDataView'owState. The filter e&pression identifies hich ros to return based on

    DataColumnvalues! such as 8ast$ame G ?Smith?. The sort e&pression follos standard SA8

    conventions for ordering columns! for e&ample 8ast$ame #S*! First$ame #S*. For rules aboutriting e&pressions! see the %&pressionproperty of the DataColumnclass.

    Tip

    f you are performing a number of calls to the Sele!tmethod of a DataTable! you can increase

    performance by first creating a"ataViefor the DataTable. *reating the DataViewinde&es theros of the table. The Sele!tmethod then usees that inde&! significantly reducing the time to

    generate the 2uery result. For information about creating a DataViewfor a DataTable! see

    "ataVies.

    The Sele!tmethod determines hich version of the ros to vie or manipulate based on a"ataVieRoState.The folloing table describes the possible DataView'owState

    enumeration values.

    DataView'owState

    alue Des!ription

    http://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-5http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.select(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarowcollection.find(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataview(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataview(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fdcwwhez(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataviewrowstate(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataviewrowstate(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/z16c79x4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-5http://void%280%29/http://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx#feedbackhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datatable.select(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarowcollection.find(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datarow(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.datacolumn.expression(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataview(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/fdcwwhez(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/system.data.dataviewrowstate(v=vs.110).aspx
  • 8/13/2019 Designing DataTables

    18/19

    Current'ows *urrent ros including unchanged! added! and modified ros.

    Deleted # deleted ro.

    3odi+iedCurrent# current version! hich is a modified version of original data. (See

    3odi+ied/riginal.)

    3odi+ied/riginal

    The original version of all modified ros. The current version is

    available using 3odi+iedCurrent.Added # ne ro.

    None $one.

    /riginal'ows Original ros! including unchanged and deleted ros.

    5n!(anged #n unchanged ro.

    n the folloing e&ample! the DataSetob/ect is filtered so that you are only oring ith roshose DataView'owStateis set to Current'ows.

    *

    V3DataRow[ currentRows = workTable.Select(

    null' null' Data/!ewRowState.CurrentRows);

    !(currentRows.Lent + # )

    Console.0r!teL!ne("No Current Rows 1ound");

    else

    &

    oreac(DataColumn column !nworkTable.Columns)

    Console.0r!te("2t&*"' column.ColumnName);

    Console.0r!teL!ne("2tRowState");

    oreac(DataRow row !ncurrentRows)

    & oreac(DataColumn column !nworkTable.Columns)

    Console.0r!te("2t&*"' row[column);

    Console.0r!teL!ne("2t"- row.RowState);

    The Sele!tmethod can be used to return ros ith differing 'owStatevalues or field values.The folloing e&ample returns a Data'owarray that references all ros that have been deleted!

    and returns another Data'owarray that references all ros! ordered by CustName! here the

    Cust*Dcolumn is greater than D. For information about ho to vie the information in the

    Deletedro! see Ro States and Ro Versions.

    *

    V333 Retr!e4e all deleted rows.

    DataRow[ deletedRows = workTable.Select(

    null' null' Data/!ewRowState.Deleted);

    33 Retr!e4e rows were Cust5D 6 7' and order b8 CustLName.

    http://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1http://msdn.microsoft.com/en-us/library/vstudio/ww3k31w0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2http://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1http://msdn.microsoft.com/en-us/library/vstudio/ww3k31w0(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/vstudio/kcs3hdk5(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
  • 8/13/2019 Designing DataTables

    19/19

    DataRow[ custRows = workTable.Select("Cust5D 6 7"' "CustLName ASC");

    See #lso

    http://void%280%29/http://void%280%29/