Working with typed Dataset in vb.net

Ratings:
(4)
Views:318
Banner-Img
  • Share this blog:

 

Working with typed Dataset:

Typed Dataset:

Whenever a Dataset is defined based on the XML schema definition file then it is said to be a typed dataset.

To create a Typed Dataset

Go to project [menu] UntitledAdd new item Untitled Under installed Templates [left menu] Untitled select data Untitled 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 Untitled click

Then the window will be opened.

Server name “Sekhar” --- differs from system to system

Check Radio button use SQL server authentication

Username: Sa

Password: 123 (***)

Check to save my password

Select or enter a database name

Select NorthWind in the 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 a form

A Message box is displayed to save the password click yes

Save ctrl + s

Project [menu] Untitled 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 a table in the form of navigation then?  

Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training

Projecting the Data using Navigation style:

Project [menu] Untitled Add Windows Form

Click on Data [menu] à Show Data Sources

We get Untitled NorthWind DC

Employees

Expand these

employees

(-) Employee Id

(-)  Last Name

(-) First Name  

Drag and drop the columns available under Employees individually on to the form like (sample)

  Form

Navigation style is achieved Navigation style  

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 it relates among tables.

Save Untitled ctrl + s

Go to project [menu] UntitledAdd Windows Form

Click on Data [menu] Untitled Show Data Sources

In the 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)

  Typed data set  

Working with Tree View control:

Let us design a sample like this

Tree view control    

Working with Tree View control:

Let us design a sample like this

  Tree view control  

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

Untitled Execute Assign

Dept Emp
Dept no Eno
Dname Ename
Loc Esal
  Job
  Dept no

     

For an in-depth knowledge, click on below

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox