0% found this document useful (0 votes)
298 views3 pages

Practical No 24 Gad 22034 1

This document discusses using ADO.Net to connect to a database and retrieve data to display in a datagrid. It provides an example code that opens an OleDB connection to an MS Access database, executes a SQL command to select all records from a table, fills a dataset using a data adapter, and binds the dataset to a datagrid's datasource. It also includes questions and an exercise related to using ADO.Net to retrieve and display data from a database in a windows form application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
298 views3 pages

Practical No 24 Gad 22034 1

This document discusses using ADO.Net to connect to a database and retrieve data to display in a datagrid. It provides an example code that opens an OleDB connection to an MS Access database, executes a SQL command to select all records from a table, fills a dataset using a data adapter, and binds the dataset to a datagrid's datasource. It also includes questions and an exercise related to using ADO.Net to retrieve and display data from a database in a windows form application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.24: Understand the concept of ADO.

Net

Practical No 24

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program using ADO.Net to the database.

Imports System.Data
Imports System.Data.OleDb

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data " &
"Source=C:\Users\Suresh\Documents\Visual Studio 2012 \ Projects \ Datagrid \
stud.mdb")
Conn.Open()
Dim cmd As New OleDbCommand("Select * From Marks", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Marks")
DataGrid1.CaptionText = "marks"
DataGrid1.DataSource = ds
DataGrid1.DataMember = "marks"

End Sub

End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.24: Understand the concept of ADO.Net

Output:

XIII. Practical related Questions


1. Find error from following code
Dim con As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0DataSource=D:\mydata.accdb;")

 Error 1 Type expected.


Error 2 'OleDbConnection' is a type and cannot be used as an expression.
Error 3 'Conn' is not declared. It may be inaccessible due to its protection level.

2. Write a connection string with MS-access using any database.


 Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDB.accdb

GUI Application Development using VB.Net (22034) Page 2


Practical No.24: Understand the concept of ADO.Net

XIV. Exercise
1. Design the windows application that will display the content of a table in MS-Access
database on DataGrid control using data adapter.

Imports System.Data
Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data” &
“Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\DataGrid1\student.mdb")
conn.Open()
Dim cmd As New OleDbCommand("Select *From Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Roll Call")
DataGrid1.CaptionText = "Student"
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Roll Call"

End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3

You might also like