You are on page 1of 10

Amit Patel

VB .Net - Practical

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Program = 7 Write a Windows Application to Insert and Delete data from database..

Change its appropriate properties of the control

Controls name
Lable1
Lable2
Lable3
Lable4
Lable5
TextBox1
TextBox2
TextBox3
TextBox4
ComboBox1
Button1
Button2

Name
Lable1
Lable1
Lable1
Lable1
Lable1
TextBox1
TextBox2
TextBox3
TextBox4
ComboBox1
CmdSave
CmdDelete

Text
Roll No
Name
Address
City
Phone No
-------------------------------------Insert
Delete

First of All declare Two Namespace


Imports System.Data
Imports System.Data.OleDb

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


--------------------------------------------------------------------------------------------------------------------------- First of All declare variables that used in your projects.
Dim Con As OleDbConnection
Dim cmd As OleDbCommand
Dim adp As OleDbDataAdapter
Dim ds As New DataSet

Connection

:: - Double Click on Form Which display following Procedure

Private Sub Form1_Load()Handles MyBase.Load


Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=D:\\Program\\Bca.accdb")
Show_Data()
End Sub

Create Show_Data Method :: -

Private Sub Show_Data()


cmd = New OleDbCommand("Select * from Student", Con)
Con.Open()
ds.Clear()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
DataGridView1.DataSource = ds.Tables(0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Create Clear Method :: -

Private Sub Clear()


TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox1.Text = ""

End Sub

Save :: - Double Click on Save Button Which display following Procedure

Private Sub CmdSave_Click() Handles CmdSave.Click


cmd = New OleDbCommand("Insert into Student Values(" + TextBox1.Text + ",
'" + TextBox2.Text + "','" + TextBox3.Text + "','" + ComboBox1.Text + "'," + TextBox4.Text +
")", Con)
Con.Open()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
MsgBox("Insert Record SuccessFully")
Clear()
Show_Data()
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Delete :: - Double Click on Delete Button Which display following Procedure

Private Sub CmdDelete_Click( ) Handles CmdDelete.Click


cmd = New OleDbCommand("Delete * from Student where Enr_No = " + TextBox1.Text + "", Con)
Con.Open()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
MsgBox("Delete Record SuccessFully")
Clear()
Show_Data()
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

Amit Patel

VB .Net - Practical

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Program = 8 Write a Windows application to View/Search and Update data from
database.

Change its appropriate properties of the control

Controls name
Lable1
Lable2
Lable3
Lable4
Lable5
TextBox1
TextBox2
TextBox3
TextBox4
ComboBox1
Button1
Button2

Name
Lable1
Lable1
Lable1
Lable1
Lable1
TextBox1
TextBox2
TextBox3
TextBox4
ComboBox1
CmdSave
CmdDelete

Text
Roll No
Name
Address
City
Phone No
-------------------------------------Add
Delete

First of All declare Two Namespace


Imports System.Data
Imports System.Data.OleDb

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


--------------------------------------------------------------------------------------------------------------------------- First of All declare variables that used in your projects.
Dim Con As OleDbConnection
Dim cmd As OleDbCommand
Dim adp As OleDbDataAdapter
Dim ds As New DataSet

Connection

:: - Double Click on Form Which display following Procedure

Private Sub Form1_Load()Handles MyBase.Load


Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=D:\\Program\\Bca.accdb")
Show_Data()
End Sub

Create Show_Data Method :: -

Private Sub Show_Data()


cmd = New OleDbCommand("Select * from Student", Con)
Con.Open()
ds.Clear()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
DataGridView1.DataSource = ds.Tables(0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Create Clear Method :: -

Private Sub Clear()


TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox1.Text = ""

End Sub

Update :: - Double Click on Update Button Which display following Procedure

Private Sub CmdUpdate_Click() Handles CmdSave.Click


cmd = New OleDbCommand("Update Student Set Name = '" + TextBox2.Text + "',Address = '" +
TextBox3.Text + "',City = '" + ComboBox1.Text + "',Phone = " + TextBox4.Text + " where Enr_No = " +
TextBox1.Text + "", Con)
Con.Open()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
MsgBox("Update Record SuccessFully")
Clear()
Show_Data()
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Search Record :: - Double Click on Search Button Which display following Procedure

Private Sub CmdSearch_Click( ) Handles CmdDelete.Click


Dim ds2 As New DataSet
cmd = New OleDbCommand("Select * from Student where Enr_No = " + TextBox1.Text + "", Con)
Con.Open()
ds2.Clear()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds2)
Con.Close()

Dim dt As DataTable = ds.Tables(0)


If dt.Rows.Count > 0 Then
TextBox2.Text = dt.Rows(0)(1).ToString()
TextBox3.Text = dt.Rows(0)(2).ToString()
ComboBox1.Text = dt.Rows(0)(3).ToString()
TextBox4.Text = dt.Rows(0)(4).ToString()
Else
MsgBox("This Record Not Present")
Clear()
Show_Data()
End If
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

Amit Patel

VB .Net - Practical

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Program = 9 Write a windows application to display data in DatagridView Control..

Change its appropriate properties of the control


Controls name
DataGridView1

Name
DataGridView1

Text
---------

First of All declare Two Namespace


Imports System.Data
Imports System.Data.OleDb
First of All declare variables that used in your projects.\
Dim Con As OleDbConnection
Dim cmd As OleDbCommand
Dim adp As OleDbDataAdapter
Dim ds As New DataSet

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


---------------------------------------------------------------------------------------------------------------------------Display Data into DataGridView :: - Double Click on Form Which display following Procedure

Private Sub Form1_Load( ) Handles MyBase.Load


Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=D:\\Program\\Bca.accdb")
cmd = New OleDbCommand("Select * from Student", Con)
Con.Open()
ds.Clear()
adp = New OleDbDataAdapter(cmd)
adp.Fill(ds)
Con.Close()
DataGridView1.DataSource = ds.Tables(0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

You might also like