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