24 Gad

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

GUI APPLICATION DEVELOPMENT USING VB.

NET (22034)
Roll No. 88

Name of Student: Ekambe Ganesh Roll No.: 88

Experiment No.: 24 DOS:

‐---------------‐-----------------------------------------------------------------------------

Code:
XI. Program Code:
Write a program using ADO.Net to connect to the database

Code:-

Imports System.Data.OleDb
Public Class Form19
Dim CON As OleDbConnection
Dim CMD As OleDb.OleDbCommand
Dim DR As OleDb.OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CON = New OleDb.OleDbConnection("PROVIDER =
MICROSOFT.JET.OLEDB.4.0;DATA SOURCE =
C:\Users\MyPC\Desktop\Student.mdb")
CON.Open()
CMD = New OleDb.OleDbCommand("SELECT * FROM StudentInfo",
CON)
DR = CMD.ExecuteReader
DR.Read()
TextBox1.Text = DR(0)
TextBox2.Text = DR(1)
TextBox3.Text = DR(2)
CON.Close()
End Sub
End Class
GUI APPLICATION DEVELOPMENT USING VB.NET (22034)
Roll No. 88

Output:-
XIII. Practical Related Questions
1. Find error from following code
Dim con As New OledbConnection
("Provider=microsoft.oledb.4.0DataSource=D:\mydata.accdb ;")
After Correcting Errors:-
Dim Con As OleDbConnection
Con=New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data
Source=D:\mydata.accdb")
2. Write a connection string with MS-access using any database. Code:-
Imports System.Data.OleDb
Public Class Database
Dim CON As OleDbConnection
Dim CMD As OleDb.OleDbCommand
Dim DR As OleDb.OleDbDataReader

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click ‘Select
Dim Srch As Integer
Srch = InputBox("Enter the Roll No To Select or Search : ")
CON = New OleDb.OleDbConnection("PROVIDER =
MICROSOFT.JET.OLEDB.4.0;DATA SOURCE =
C:\Users\MYPC\Desktop\Student.mdb")
CON.Open()
CMD = New OleDb.OleDbCommand("SELECT * FROM StudentInfo
where
RollNo=" & Srch, CON)
DR = CMD.ExecuteReader
DR.Read()
TextBox1.Text = DR(0)
GUI APPLICATION DEVELOPMENT USING VB.NET (22034)
Roll No. 88
TextBox2.Text = DR(1)
TextBox3.Text = DR(2)
CON.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click ‘Insert

CON = New OleDb.OleDbConnection("PROVIDER =


MICROSOFT.JET.OLEDB.4.0;DATA SOURCE =
C:\Users\MYPC\Desktop\Student.mdb")
CON.Open()
CMD = New OleDb.OleDbCommand("INSERT INTO
StudentInfo(RollNo,Name,Class) values(' " & TextBox1.Text & " ',' " &
TextBox2.Text & " ',' " & TextBox3.Text & " ')", CON)
DR = CMD.ExecuteReader
MsgBox("Record Inserted Sucessfully")
CON.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click ‘Update
Dim S As Integer
S = InputBox("Enter Roll No to Update :")
CON = New OleDb.OleDbConnection("PROVIDER =
MICROSOFT.JET.OLEDB.4.0;DATA SOURCE = C:\Users\MYPC\Desktop\
Student.mdb")
CON.Open()
CMD = New OleDb.OleDbCommand("Update StudentInfo set
Class='CO4I'
Where RollNo=" & S, CON)
DR = CMD.ExecuteReader
MsgBox("Record Updated Sucessfully")
CON.Close()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click ‘Delete
Dim D As Integer
D = InputBox("Enter Roll No to Delete : ")
GUI APPLICATION DEVELOPMENT USING VB.NET (22034)
Roll No. 88
CON = New OleDb.OleDbConnection("PROVIDER =
MICROSOFT.JET.OLEDB.4.0;DATA SOURCE =
C:\Users\MYPC\Desktop\Student.mdb")
CON.Open()
CMD = New OleDb.OleDbCommand("DELETE FROM StudentInfo
where
RollNo=" & D, CON)
DR = CMD.ExecuteReader
MsgBox("Record Deleted Sucessfully")
CON.Close()
End Sub
End Class

Output:-

XIV. Exercise
1. Design the windows application that will dispaly the content of a table in
MSAccess database on DataGrid control using data adapter. Code:-

Imports System.Data.OleDb
Public Class Form21
Dim CON As OleDb.OleDbConnection
Dim DA As OleDb.OleDbDataAdapter
Dim DS As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CON = New
OleDb.OleDbConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0;DAT
A SOURCE =
GUI APPLICATION DEVELOPMENT USING VB.NET (22034)
Roll No. 88
C:\Users\MYPC\Desktop\Student.mdb")
CON.Open()
DA = New OleDb.OleDbDataAdapter("SELECT * FROM StudentInfo",
CON)
DA.Fill(DS, "StudentInfo")
CON.Close()
DataGridView1.DataSource = DS.Tables(0)
End Sub
End Class
Output:-

You might also like