VB Net Data Access SF 10
VB Net Data Access SF 10
Net
Database Tools and Data Binding
ISYS 512
Database Processing
Querying database
Updating database:
Insertion, deletion, modification
Adapter
Connection
Dataset
SQL Updates
Data Consumer
WinForm
Command
WebForm
Reader
ADO.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.
Data Providers
ODBC Provider
Open Database Connectivity
A driver manager
Used for relational databases
OLE DB Provider
OLE DB interfaces provide applications with uniform access to
data stored in diverse information sources, or data stores.
Access
Etc.
Using ODBC
Windows XP:
Control Panel /Administrative Tools/DataSource(ODBC)
Demo:
Excel: Data/Get External Data/From other sources
Access: File/Get External Data/Import, then select
ODBC data source
proc sql;
connect to odbc (dsn=MySalesDB2007);
Create table sasuser.TEST
As select * from connection to ODBC
(select * from customer);
disconnect from odbc;
quit;
proc sql;
select * from sasuser.test;
Server Explorer
Data connections: Right click data connection
Add Connection
Tables, Views
Server name:
LocalServerName\SQLExpress
EID
Ename
Sex
Salary
HireDate
Enter data
Char 10
Char 30
Char 1
Numeric (10,2)
Date
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 controls Data Source and
Data Member to bind the data.
Dataset:
Edit in dataset designer
Binding Source
Add query: Add a new tool strip.
Preview data
Binding navigator
Code view: Form load event
Generated Code
Private Sub CUSTOMERBindingNavigatorSaveItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
CUSTOMERBindingNavigatorSaveItem.Click
Me.Validate()
Me.CUSTOMERBindingSource.EndEdit()
Me.CUSTOMERTableAdapter.Update(Me.SalesDBDataSet.CUSTOMER)
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'SalesDBDataSet.CUSTOMER' table. You can move, or remove it, as
needed.
Me.CUSTOMERTableAdapter.Fill(Me.SalesDBDataSet.CUSTOMER)
End Sub
Hierarchical Forms
Parent table/Child table
Add parent table and child table to Data Source
Drag the parent table and the child table to the form.
Parent table uses detail view and child table uses
dataGrid view
Click Dataset objects smart tag to choose Edit in
Dataset Designer
With the designer, right click the parent table and
choose Add/Relation
Change dataGrids DataSource property to the relation.
DisplayInfo
Enter New
Modify
Exit
Me.BindingContext(DataSet21, "customer").Position += 1
MoveLast:
Me.BindingContext(DataSet21, "customer").Position =
Me.BindingContext(DataSet21, "customer").Count -1
Methods:
BindingSource1.EndEdit()
OleDbDataAdapter1.Update(DataSet21.CUSTOMER)
End Sub
Binding ListBox
Example: Bind Customer Tables 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.
Unbound textbox
To display the ValueMember
Textbox1.text = ListBox1.SelectedValue