You are on page 1of 2

Imports System.Data.

OleDb

Public Class Form1

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HP\Documents\student3.accdb")

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'TODO: This line of code loads data into the 'Student3DataSet.student3' table. You can move, or remove it, as needed.

Me.Student3TableAdapter.Fill(Me.Student3DataSet.student3)

conn.Open()

Datadisplaygridview()

End Sub

Public Sub Datadisplaygridview()

Dim DA As New OleDbDataAdapter("select * from student3", conn)

Dim Dt As New DataTable

DA.Fill(Dt)

DataGridView1.DataSource = Dt

conn.Close()

End Sub

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

Dim str As String

str = "insert into student3 values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"

Dim cmd As New OleDbCommand(str, conn)

conn.Open()

cmd.ExecuteNonQuery()

conn.Close()

Datadisplaygridview()

End Sub

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

conn.Open()

Dim str As String

str = "update student3 set Field1=('" & TextBox2.Text & "'),Field2=('" & TextBox3.Text & "') where ID=(" & TextBox1.Text & ")"

Dim cmd As New OleDbCommand(str, conn)

cmd.ExecuteNonQuery()

conn.Close()

Datadisplaygridview()

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


conn.Open()

Dim str As String

str = "delete from student3 where id=(" & TextBox1.Text & ")"

Dim cmd As New OleDbCommand(str, conn)

cmd.ExecuteNonQuery()

conn.Close()

Datadisplaygridview()

End Sub

End Class

You might also like