Write a VB.Net program to accept the details of Employee (ENO, EName, Salary) and store them into the database and display them in a GridView control.

Answer:

Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Desktop\New folder\Emp.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Emp", con)
    Dim ds As New DataSet
    Dim cmd As New OleDbCommand
    Public Function display()
        adpt.Fill(ds, "Emp")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "Emp"
        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 Emp values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ")"
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
        ds.Clear()
        display()
    End Sub
End Class
Scroll to Top