Unformatted text preview:

VB .NET Database AccessMicrosoft Universal Data AccessSlide 3Using ODBCVB.NET Database ToolsSteps to Retrieve DataADO.NET ObjectsSlide 8How to create an ADO.Net object?Data Form WizardAdapter & Dataset Context MenuOther Data Form DemosCreating A Database Application Without ProgrammingData Adapter WizardData BindingCreating Bound ControlsBinding Text BoxMoveNext and MoveLast ExampleCurrencyManagerBinding DataGridDisplaying Many Tables with One DataGridCreating Hierarchical Data GridBinding ListBoxDisplay Selected RecordListBox SelectedItem PropertyUsing Object BrowserCollection StructureNavigate and Display Records in Unbound Text BoxesImplement MoveNext Button with Unbound ControlUsing Object Browser to Study OleDB ObjectSearching with the Find Method Another Way to Bind Listbox and Display Selected RecordCode ExampleHow to Determine If Record Exists or NotCreating Parameter Query with Adapter Configuration WizardParameter Query Example:Display Selected Record in Text Boxes with Parameter QuerySend Changes in a Bound DataGrid Back to the DatabaseCreating Parent/Child Form with BindingVB .NET Database AccessISYS546Microsoft Universal Data Access•ODBC: Open Database Connectivity–A driver manager–Used for relational databases•OLE DB: The OLE database protocol–Allows a program to access information in many types of data source.–Data provider: databases, spreadsheets, etc.•ADO.NET: ActiveX Data Objects–An Interface for OLE DB.–Allow programmers to use a standard set of objects to refer to any OLE DB data source..Net ApplicationsOLE DBProviderOLE DBData SourceOLE DBProviderODBCODBCData SourceSQL Server Data SourceSQL Server .Net Data ProviderOLE DB .Net Data ProviderADO.NetUsing ODBC•Windows 2000/2003: •Control Panel /Administrative Tools/DataSource(ODBC)•Three types of data source names–User DSN: usable only by you and only on the machine currently using.–System DSN: Any one using the machine can use.–File DSN: Can be copied and used by other computers with the same driver installed.VB.NET Database Tools•Database connection:–Tool/Connect to database•Provider:MS Jet 4.0 OLE DB Provider•Connection•Server Explorer–Data connections:•Right click and Add Connection•Tables, Views•Toolbox:Data tab•Data Form WizardSteps to Retrieve Data •Establishes a connection to the database.•Executes commands against the database.•Store data results.ADO.NET ObjectsData Set.NET ApplicationsData ReaderCommand ObjectConnection ObjectDatabaseAdapterADO.NET Objects•Connection Object: Represent a connection to the database. •Command Object: The command object allows us to execute a SQL statement or a stored procedure.•DataReader: It is a read-only and forward-only pointer into a table to retrieve records.•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.How to create an ADO.Net object?•Using Wizard–Data Form Wizard–Data Adapter Wizard•Using code: –Example:–dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb"–dim objConn as new OledbConnection(strConn)–objConn.open()Data Form Wizard•Creating a form with ADO.Net objects and data-bound controls to display and update information in a dataset.•Demo: Using Data Form Wizard to create a navigational form.–Project/Add Windows Form/Data Form Wizard–Set connection–Choose tables–Display records in grid or in text boxes.Adapter & Dataset Context Menu•Adapter:–Properties:•Command objects–Configure Adapter–Generate dataset–Preview data•Dataset:–View Schema: Dataset/XMLOther Data Form Demos•Display records in text boxes.•Add /Modify/Delete records.•Hierarchical forms:–Parent/Child relationshipCreating A Database Application Without Programming•Creating a database application to display information and update database.•A main form with buttons to open data forms:–DisplayInfo–Enter New–Modify–ExitData Adapter Wizard•Configure Data Adapter and generating a dataset:–Drag OledbDataAdapter (or database’s table) to the form.–Use the Data Adapter Wizard to configure the Adapter.–Right Click the Adapter to preview data and creating dataset.•Bind the dataset to controls.Data Binding•Connect a control or property to one or more data elements.•Simple binding: Use simple binding to display a field value in controls that show Data Bindings in the property window, such as text box or label.•Complex binding: Use complex binding to bind more than one field to controls such as DataGrid and list box. Use the control’s Data Source and Data Member to bind the data.Creating Bound Controls•DataGrid control:–Data Source property–Data Member property–In the Form Load event, use Adapter’s Fill method to load the dataset:•OleDbDataAdapter1.Fill(DataSet11)Binding Text Box•Data Bindings property:–Text: choose field•Add navigation buttons:–The current record position within the dataset is stored in a form’s BindingContext’s Position property. This position is zero based. Add one move to the next record, minus one move to the previous record.MoveNext and MoveLast Example•MoveNext:– Me.BindingContext(DataSet21, "customer").Position += 1•MoveLast:–Me.BindingContext(DataSet21, "customer").Position = Me.BindingContext(DataSet21, "customer").Count -1•How to MovePrevious and MoveFirst?•Note: The Position property takes care of the end of file automatically.CurrencyManager•Dim custCurrMgr As CurrencyManager•Dim ordCurrMgr As CurrencyManager•In a procedure:–ordCurrMgr = Me.BindingContext(Ds31, "orders")–custCurrMgr = Me.BindingContext(Ds31, “customer")–custCurrMgr.Position += 1–ordCurrMgr.Position += 1Binding DataGrid•From Server Explorer, drag the table from a database connection (or from Data tab, drag a oleDbAdapter) onto the form.•Create dataset.•Drag DataGrid and set the DataSource and Data Member property.•Use adapter’s Fill method to load the dataset.Displaying Many Tables with One DataGrid•Define one Adapter for each table.•Create the dataset with multiple tables.•Add a DataGrid control and set the DataSource proeprty to the dataset name and leave the DataMember property blank.Creating Hierarchical Data Grid•Define two Adapters, one for the parent table and one for the child table.•Create the dataset.•Right-click the dataset


View Full Document

SF State ISYS 546 - VB NET Data Access

Download VB NET Data Access
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view VB NET Data Access and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view VB NET Data Access 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?