Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.

Similar presentations


Presentation on theme: "Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of."— Presentation transcript:

1 Using Adapter Wizard ISYS 512

2 Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of the ToolBox, Drag SqlDataAdapter to the form. –Use the Data Adapter Wizard to configure the Adapter. –Right Click the Adapter to preview data and create dataset. Note: If SqlDataAdapter is not listed in Toolbox’s Data tab, right click ToolBox Data Tab and select Choose Item; then select SqlDataAdapter from.Net Framework components.

3 Creating a Form with Bound DataGridView Configure Adapter and generate dataset. Bind DataGridView control to the table: –Data Source property: DataSet –Data Member property A table in the dataset In the Form Load event, use Adapter’s Fill method to load the dataset: SqlDataAdapter1.Fill(DataSet11); Note 1: No navigation capability Note 2: View adapter’s properties and see the SQL commands.

4 Bind Controls to BindingSource Object for one-record-at-a-time navigation Configure Adapter and generate dataset. Drag the BindingSource object from Toolbox Data tab to the form. Use BindingSource object’s property window to set its DataSource and Data Member properties to the dataset object and table object. Set control’s DataBinding property to the BindingSource object.

5 Creating a Form with Bound Textboxes Configure Adapter and generate dataset. Add and define a bindingSource object Select textbox’s Data Bindings property: –Text: choose field from bindingSOurce object In the Form Load event, use Adapter’s Fill method to load the dataset: SqlDataAdapter1.Fill(DataSet11) Note: No navigation capability

6 Using BindingSource Object to Do the Binding and Navigation It is an object that keeps track of position (the current row) of a data source. Useful properties: –DataSource –DataMember –Position property: is the index of the current row. The index is a 0- based index, the first record has a position of 0. Methods: –MoveFirst, MoveLast, MoveNext, MovePrevious –AddNew –AllowEdit –EndEdit –Current –RemoveCurrent

7 Use BindingSource Object’s MoveNext, MovePrevious Methods Add a MoveNext button –bindingSource1.MoveNext(); Add a MovePrevious button: – bindingSource1.MovePrevious();

8 Adding AddNew and Save Button AddNew button: Use BindingSource AddNew Method : private void button3_Click(object sender, EventArgs e) { bindingSource1.AddNew(); } Save button: Use BindingSource EndEdit method and Adapter’s Update method: private void button4_Click(object sender, EventArgs e) { bindingSource1.EndEdit(); SqlDataAdapter1.Update(dataSet2.CUSTOMER); }

9 Binding ListBox Example: Bind Customer Table’s CID field to a listbox. –Create a Adapter for Customer table, and generate the dataset. –Add ListBox and set binding properties: Data Source: Customer table Display Member: Field to display in the listbox. Value Member: the actual values for items in the list box.

10 Display Selected Record Bound textbox (same data source as the listbox): –If the Listbox and the textbox are bound to the same BindingSource object, the textbox will automatically displays the record of the selected listbox item.

11 Working with OleDB Data Adapter Use OleDB provider to work with another databases such as Oracle, MS Access, etc. From the Data tab: –Choose: OleDBDataAdapter –(If you don’t see it, right-click the Data tab and select Choose Item. Then select it from the.Net components)

12 DataSet and Data Adapter DataSet Object: A DataSet object can hold several tables and relationships between tables. DataAdapter: This the object used to pass data between the database and the dataset. –It is an object with SQL Select, Insert, Update and Delete commands.

13 Creating Parent/Child Form Using DataAdapter Wizard Add two DataAdapters to the form: one for the parent table and one for the child table. Use the parent table’s DataAdapter to generate a dataset; then use the child table’s DataAdapter to generate the child table into the same dataset. Open dataset’s designer and right-click the parent table and choose Add/Relation to add a relation. Add and bind textboxes to the parent table; add dataGridView and bind its datasource property to the relation. Add navigation button’s using parent table’s BindingSource object.


Download ppt "Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of."

Similar presentations


Ads by Google