Chapter 24 Quick Reference


Chapter 24 Quick Reference

To

Do this

Define a new DataSet.

Click Add New Item in the Project menu and select the DataSet template. Give the DataSet filename an extension of “.xsd.”

Add a DataTable and TableAdapter to a DataSet.

Open the DataSet Designer window. Using the Toolbox, add a TableAdapter to the DataSet. Use the TableAdapter Configuration Wizard to define the DataTable and the TableAdapter methods.

Use simple binding to bind a property of a control to a data source at design time.

Expand the DataBindings property of the control. Click the property you want to bind to and select the data source to use.

Use simple binding to bind a property of a control to a data source at run time.

Use the Add method of the DataBindings property.

Specify the property to bind to and the data source. For example, to bind the Text property of the Button control named button1 to the Text property of the textBox1 control, use the following code:

myLabel.DataBindings.Add("Text", textBox1, "Text");

Use complex binding to bind a ListBox, ComboBox, or CheckedListBox control to a list of values from a data source.

Set the DataSource property of the control.

Specify the data to be displayed using the DisplayMember property, and then specify the data to be used as the value of the control by using the ValueMember property.

Use complex binding to bind a DataGridView control to a list of values from a data source.

Set the DataSource property of the control.

Optionally, specify the data to be displayed and edited using the DataMember property.

Constrain user input in a DataGridView control.

Right-click the DataGridView control in the Design View window and click Edit Columns. Use the Edit Columns dialog box to set the ColumnType and ReadOnly properties of the control.

If you set the ColumnType property to DataGridViewComboBox, set the DataSource, DisplayMember, and ValueMember properties as for performing complex binding.

Validate user input in a DataGridView control.

Use the CellValidating event to perform validation when the user modifies a cell and tries to move away.

Use the CellEndEdit event to clear any error messages after the cell has been successfully validated.

Use the DataError event to trap any other user input errors.

Validate the changes the user has made to the data in a DataSet.

For each DataTable in the DataSet, call the GetErrors method to find all of the rows containing errors. For each row found, use the GetColumnsInError method to iterate through all the columns that contain errors, and for each column, call the GetColumnError method to obtain the details of the error for that column.

Update the database with the information in a DataSet.

Run the Update method of the TableAdapter object passing the DataSet as the parameter. If the updates are successful, call AcceptChanges on the DataSet; otherwise call RejectChanges.




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net