0% found this document useful (0 votes)
13 views6 pages

Exp 25 & 26

Uploaded by

moreprajwal083
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Exp 25 & 26

Uploaded by

moreprajwal083
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF COMPUTER

ENGINEERING

Subject: GUI Application Development using Subject Code:22034


VB.NET
Semester: 04 Course: CO4I-B
Laboratory No: L001B Name of Subject Teacher: Prof. Poonam Pandire
Name of Student: Prajwal More Roll ID: 22203B0048

Experiment No: 25 & 26


Title of Experiment Understand the Concept of Data Adapter

 Write a program using data adapter to connect to the database.


Program:
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\Purva\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

Output:
 Practical Related Questions

1) Find error in following code


Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from Customers",
connection)
Dim ds As DataSet = New DataSet()
Fill(ds)
Error:
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 data adapter syntax using a MS-Access code with a student table.
Ans: Dim da As OleDbDataAdapter
Da=New OleDbDataAdapter(cmd)

 Exercise

1) Design a window application in MS-Access which have navigation (Next, First, Previous,
Last).
Program:
Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.student' table. You can
move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.Db1DataSet.student)
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Purva\Documents\Visual Studio 2012\Projects\Nav2\db1.mdb")
con.Open()
cmd = New OleDbCommand("Select * From student", con)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "student")
Me.TextBox1.DataBindings.Add("text", ds, "student.RollNo")
Me.TextBox2.DataBindings.Add("text", ds, "student.Name")
Me.TextBox3.DataBindings.Add("text", ds, "student.Marks")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.BindingContext(ds, "student").Position = 0
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.BindingContext(ds, "student").Position = Me.BindingContext(ds,
"student").Position + 1
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.BindingContext(ds, "student").Position = Me.BindingContext(ds,
"student").Position – 1
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.BindingContext(ds, "student").Position=Me.BindingContext(ds,"student").Count-1
End Sub
End Class

Output:

2) Develop a window application that will contain multiple tables in a single dataset.
Program:
Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.BindingContext(ds, "student").Position=Me.BindingContext(ds,"student").Count-1
End Sub
End Class
OUTPUT:
2. Develop a windows application that will contain multiple tables in a single dataset.

Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Purva\Documents\Visual Studio 2012\Projects\Multiple
Table\db1.mdb")
con.Open()
Dim cmd1 As New OleDbCommand("Select * From student", con)
Dim cmd2 As New OleDbCommand("Select * From subjects", con)
Dim da1 As New OleDbDataAdapter(cmd1)
Dim da2 As New OleDbDataAdapter(cmd2)
Dim ds As New DataSet
DataGrid1.CaptionText = "Student Record"
DataGrid2.CaptionText = "Subject Details"
da1.Fill(ds, "student")
da2.Fill(ds, "subjects")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
DataGrid2.DataSource = ds
DataGrid2.DataMember = "subjects"
End Sub
End Class

Output:
Marks Obtained Dated signature of Teacher

Process Product Total (50)


Related (35) Related (15)

You might also like