0% found this document useful (0 votes)
148 views10 pages

Amit Patel: Program 7 Write A Windows Application To Insert and Delete Data From Database

This document provides code for several VB.NET programs that perform database operations using a Windows Forms application and an Access database. It includes code to insert and delete records, display and search records in a datagrid, and update records. The code declares variables, connects to the database, runs SQL commands to manipulate or retrieve data, and displays results in controls like labels, textboxes and a datagrid.

Uploaded by

vjpvjpvjpvjp
Copyright
© Attribution Non-Commercial (BY-NC)
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)
148 views10 pages

Amit Patel: Program 7 Write A Windows Application To Insert and Delete Data From Database

This document provides code for several VB.NET programs that perform database operations using a Windows Forms application and an Access database. It includes code to insert and delete records, display and search records in a datagrid, and update records. The code declares variables, connects to the database, runs SQL commands to manipulate or retrieve data, and displays results in controls like labels, textboxes and a datagrid.

Uploaded by

vjpvjpvjpvjp
Copyright
© Attribution Non-Commercial (BY-NC)
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

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 [Link]
Imports [Link]

_____________________________________________________________________
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 [Link]


Con = New OleDbConnection("Provider=[Link].12.0;
Data Source=D:\\Program\\[Link]")
Show_Data()
End Sub

Create Show_Data Method :: -

Private Sub Show_Data()


cmd = New OleDbCommand("Select * from Student", Con)
[Link]()
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
[Link] = [Link](0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


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

Private Sub Clear()


[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""

End Sub

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

Private Sub CmdSave_Click() Handles [Link]


cmd = New OleDbCommand("Insert into Student Values(" + [Link] + ",
'" + [Link] + "','" + [Link] + "','" + [Link] + "'," + [Link] +
")", Con)
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
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 [Link]


cmd = New OleDbCommand("Delete * from Student where Enr_No = " + [Link] + "", Con)
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
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 [Link]
Imports [Link]

_____________________________________________________________________
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 [Link]


Con = New OleDbConnection("Provider=[Link].12.0;
Data Source=D:\\Program\\[Link]")
Show_Data()
End Sub

Create Show_Data Method :: -

Private Sub Show_Data()


cmd = New OleDbCommand("Select * from Student", Con)
[Link]()
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
[Link] = [Link](0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

VB .Net - Practical

Amit Patel

AMPICS BCA College, Kherva


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

Private Sub Clear()


[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""

End Sub

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

Private Sub CmdUpdate_Click() Handles [Link]


cmd = New OleDbCommand("Update Student Set Name = '" + [Link] + "',Address = '" +
[Link] + "',City = '" + [Link] + "',Phone = " + [Link] + " where Enr_No = " +
[Link] + "", Con)
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
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 [Link]


Dim ds2 As New DataSet
cmd = New OleDbCommand("Select * from Student where Enr_No = " + [Link] + "", Con)
[Link]()
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds2)
[Link]()

Dim dt As DataTable = [Link](0)


If [Link] > 0 Then
[Link] = [Link](0)(1).ToString()
[Link] = [Link](0)(2).ToString()
[Link] = [Link](0)(3).ToString()
[Link] = [Link](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 [Link]
Imports [Link]
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 [Link]


Con = New OleDbConnection("Provider=[Link].12.0;
Data Source=D:\\Program\\[Link]")
cmd = New OleDbCommand("Select * from Student", Con)
[Link]()
[Link]()
adp = New OleDbDataAdapter(cmd)
[Link](ds)
[Link]()
[Link] = [Link](0)
End Sub

_____________________________________________________________________
BCA Sem IV
Ganpat University

You might also like