Professional Documents
Culture Documents
.Net Applications
ADO.Net
SQL Server
OLE DB
.Net Data Provider .Net Data Provider
SQL Server
Data Source
OLE DB
Provider
OLE DB
Provider
ODBC
OLE DB
Data Source
ODBC
Data Source
Using ODBC
Windows 2000/2003:
Control Panel /Administrative Tools/DataSource(ODBC)
Server Explorer
Data connections:
Right click and Add Connection
Tables, Views
Toolbox:Data tab
Data Form Wizard
ADO.NET Objects
.NET Applications
Data Set
Adapter Data Reader
Command Object
Connection Object
Database
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.
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()
Configure Adapter
Generate dataset
Preview data
Dataset:
View Schema: Dataset/XML
DisplayInfo
Enter New
Modify
Exit
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.
Me.BindingContext(DataSet21, "customer").Position += 1
MoveLast:
Me.BindingContext(DataSet21, "customer").Position =
Me.BindingContext(DataSet21, "customer").Count -1
CurrencyManager
Dim custCurrMgr As CurrencyManager
Dim ordCurrMgr As CurrencyManager
In a procedure:
Binding 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 adapters Fill method to load the
dataset.
Binding ListBox
Example: Bind Customer Tables CID field to a
listbox.
Create a Adapter to retrieve CID (and Cname) fields ,
and generate the dataset.
Add ListBox and set binding properties:
Data Source
Display Member
Value Member: the actual values for items in the list box. To
display the selected items value in a text box, do:
Textbox1.text = ListBox1.SelectedValue
Unbound textbox
Item property
Collection Structure
Properties:
Count
Item(index), 0-based index
Methods:
Clear, Add, Insert, Remove, etc.
TextBox4.Text = drFound.Item("cname")
Or drFound.Item(1)
Or: TextBox4.Text =
DataSet11.CUSTOMER.Rows(0).Item(1)
Or: DataSet21.Tables.Item("customer").Rows.Item(0).Item(1)
Else
MsgBox("out of bound")
End If
Note: MovePrevious, MoveLast, MoveFirst?
OleDBCommannd
Methods: ExecuteReader, ExecuteNonQuery
Properties: Connection, CommandType, CommandText,
Parameters
OleDBDataAdapter
Methods: Fill
Properties: SelectCommand, InsertCommand, DeleteCommand,
UpdateCommand.
Code Example
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Dim drFound As DataRow
drFound = DataSet41.CUSTOMER.Rows.Find(ListBox1.SelectedValue)
Assume SelectedValue is CID
TextBox1.Text = drFound.Item("cname")
TextBox2.Text = drFound.Item("rating")
End Sub
Note: We can get the search value from other controls such as InputBox
and Textbox.