Write a VB.NET program to accept the details of a Supplier (SupId, SupName, Phone No, Address), store it in the database, and display it.

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\Supplier.accdb")

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

    Dim cmd As New OleDbCommand

    Dim ds As New DataSet

    Public Function display()

        adpt.Fill(ds, "Supplier")

        DataGridView1.DataSource = ds

        DataGridView1.DataMember = "Supplier"

        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 Supplier values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ",'" & TextBox4.Text & "')"

        con.Open()

        If cmd.ExecuteNonQuery() Then

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

        End If

        con.Close()

        ds.Clear()

        display()

    End Sub

End Class
Scroll to Top