0% found this document useful (0 votes)
30 views2 pages

CRUD in

This document contains code for a form that allows adding, viewing, updating, and deleting records in a database table using Visual Basic and OleDb. It connects to an Access database, builds SQL statements, and executes queries to perform CRUD operations on a student table.

Uploaded by

ANIK DUTTA
Copyright
© © All Rights Reserved
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)
30 views2 pages

CRUD in

This document contains code for a form that allows adding, viewing, updating, and deleting records in a database table using Visual Basic and OleDb. It connects to an Access database, builds SQL statements, and executes queries to perform CRUD operations on a student table.

Uploaded by

ANIK DUTTA
Copyright
© © All Rights Reserved
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
You are on page 1/ 2

Imports System.Data.

OleDb
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim conn = New OleDb.OleDbConnection

conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.accdb"

conn.Open()

Dim sql As String = "Insert into stud values(" & Val(TextBox1.Text) & ",'" & TextBox2.Text & "','" &
TextBox3.Text & "','" & TextBox4.Text & "','" & DateTimePicker1.Text & "')"

Dim cmd As New OleDb.OleDbCommand(sql, conn)

Dim t As Integer = cmd.ExecuteNonQuery

MsgBox("Record Added")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Dim conn = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.accdb"
conn.Open()

Dim sql As String = "select *from stud"


Dim cmd As New OleDb.OleDbCommand(sql, conn)

Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
Dim dt = New DataTable
dt.Load(dr)
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = dt
DataGridView1.Refresh()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim conn = New OleDb.OleDbConnection

conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.accdb"

conn.Open()

Dim sql As String = "UPDATE stud SET Roll=" & Val(TextBox1.Text) & ",Name='" & TextBox2.Text &
"',Father's_Name='" & TextBox3.Text & "',Mother's_Name='" & TextBox4.Text & "',Date_Of_Birth='" &
DateTimePicker1.Text & "' WHERE Roll=" & Val(TextBox1.Text) & ""

Dim cmd As New OleDb.OleDbCommand


cmd.Connection = conn
cmd.CommandText = sql

Dim t As Integer = cmd.ExecuteNonQuery

MsgBox("Record Updated")
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click


Dim conn = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.accdb"
conn.Open()
Dim sql As String = "delete from stud where roll=" & Val(TextBox1.Text)
Dim cmd As New OleDb.OleDbCommand(sql, conn)
cmd.ExecuteNonQuery()
MsgBox("Record Deleted")
End Sub
End Class

You might also like