Working with typed Dataset:
Typed Dataset:
Whenever a Dataset is defined based on the XML schema definition file then it is said to be typed dataset.
To create a Typed Dataset
Go to project [menu] Add new item
Under installed Templates [left menu]
select data
select Dataset [middle menu]
Name: NorthWindDs.Xsd
Click Add
Click on server Explorer
Rclick on Data Connections à click on add connections
Choose Data Source
Data Source
[Microsoft Account Database fib
Microsoft SQL Server — ]select this
Continue click
Then window will be opened.
Server name “sekhar” — differs from system to system
Check Radio button use SQL server authentication
Username: Sa
Password: 123 (***)
Check save my password
Select or enter a database name
Select NorthWind in drop down list
Click on [Test Connection]
Test connection successful [OK]
The above steps address a new Data Connection to server Explorer.
Under Tables in Server Explorer
Select Employees tables and drag and drop the table on form
A Message box is displayed to save password click yes
Save ctrl + s
Project [menu] Add Windows Forms
Click on Data [menu] à Show Data Sources
We will get a list of NorthWind DS – Employees
Select Employees and drag and drop on the form.
Select Dock property = till
Execute
Then we get a Table
If the client wants table in the form of navigation then ?
Projecting the Data using Navigation style:
Project [menu] Add Windows Form
Click on Data [menu] à Show Data Sources
We get NorthWind DC
Employees
Expand this employees
(-) Employee Id
(-) Last Name
(-) First Name
Drag and drop the columns available under Employees individually on to the form like (sample)
Navigation style is achieved
Establishing Data Relations using Typed Data Set:
Open NorthWindDs.Xsd
Open ServerExplorer
Drag and drop categories and products
Tables on to NorthWindDs.Xsd
If any relation exists if relates among tables.
Save ctrl + s
Go to project [menu] Add Windows Form
Click on Data [menu] Show Data Sources
In Data Source list table we get categories, products tables
Expand categories table
Drag and drop required columns from the categories table on to the form (like)
Working with Tree View control:
Let us design a sample like this
Working with Tree View control:
Let us design a sample like this
Take a new WINFORM
Drag & drop Tree View control
Set Dock = left
Drag & drop splitter control
Drag & drop Group box on form (Rside)
Resize Group box
Drag & drop 4 labels, 4 text boxes, and button in Group box
Select text for Group box as project Details
(Form6_Load)
Above Imports System.Data
Imports System.Data.SqlClient
‘Form Declarations
Dim cn as SqlConnection
Dim cn as SqlCommand
Dim da as SqlDataAdapter
Dim ds as DataSet
Dim dr as SqlDataReader
For Form_Load
Cn = New SqlConnection (“user id = sa; password = 123; database = northwind; data source = sekhar”)
da = New SqlDataAdapter (“Select * from categories”, cn)
ds = New DataSet
da.Fill (ds, “Products”)
cmd = New Sql Command (“Select * from categories”, cn)
if cn.State = ConnectionState closed then
cn.Open ()
End if
dr = cmd.Executereader
Dim root as New TreeNode
Root Text = “Available Products”
While dr.Read
Executes the loop till records are present in Data Reader
Dim Parent as new Tree Node
Parent.text = dr.GetValue (1)
For r as integer = 0 to ds.Tables (“Products”).Rows.Count -1
If dr.GetValue (0) = ds.Tables (“Products”)
Rows (r) (“CategoryId”) Then
Dim child as New treeNode
Child.text = ds.Tables (“Products”. Rows (r) (“Product Name”)
Child.Tag = ds.Tables (“products”).Rows (r) (“Product Id”)
Parents.Nodes.Add (Child)
End if
Next
Root Nodes.Add (parent)
End while
TreeView l.Nodes.Add (root)
ds.Tables (“Products”).Constrints.Add (“Pid_Pk”,
ds.tables (“Product”).Columns (“Product Id”), True)
Double click on Tree View Control:
‘TreeView1_After Select
If e.Node.Text <> “Available Products” Then
If e.Node.ParentText <> “Available Products” Then
Dim row as DataRow
Row = ds.Tables (“Products”).Rows.Find (e.Node.Tag)
txtProductId.Text = row (“Product Id’)
txtProductName.Text = row (“Product Name”)
txtQuantity.Text = row (“Quantity per Unit’)
txtPrice.Text = row (“Unit Price’)
End if
End if
Execute
Assign
Dept | Emp |
Dept no | Eno |
Dname | Ename |
Loc | Esal |
Job | |
Dept no |
0 Responses on Working with typed Dataset in vb.net"