Write a VB.NET program to create an Author table (aid, aname, book_name). Insert up to 5 records. Delete the record of the author who has written ‘VB.NET book’ and display the remaining records on the DataGridView. (Use MS Access to create the database.)

answer:

Imports System.Data.OleDb

Public Class Form1

    Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\Author.accdb")

    Dim adpt As New OleDbDataAdapter("Select * from Author", con)

    Dim cmd As New OleDbCommand

    Dim ds As New DataSet

    Public Function display()

        adpt.Fill(ds, "Author")

        DataGridView1.DataSource = ds

        DataGridView1.DataMember = "Author"

        Return ds

    End Function

 

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

        display()

    End Sub

 

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

        cmd.Connection = con

        cmd.CommandType = CommandType.Text

        cmd.CommandText = "insert into Author values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"

        con.Open()

        If cmd.ExecuteNonQuery() Then

            MessageBox.Show("Inserted Successfully...!")

        End If

        con.Close()

        ds.Clear()

        display()

    End Sub

 

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

        cmd.Connection = con

        cmd.CommandType = CommandType.Text

        cmd.CommandText = "DELETE FROM Author WHERE book_name='" & TextBox3.Text & "'"

        con.Open()

        If cmd.ExecuteNonQuery() Then

            MessageBox.Show("Deleted Successfully...!")

        End If

        con.Close()

        ds.Clear()

        display()

    End Sub

End Class

Scroll to Top