.NET Practical Slip 1 Q.B

This practical demonstrates how to accept employee details such as Employee Number, Name, and Salary using a VB.NET Windows Forms application, store the data into a database, and display the stored records using a GridView control. It helps students understand database connectivity and data presentation in VB.NET.

Slip-1 Q.B) 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. 25 Marks

Answer:

Algorithm / Logic

  1. Start the application.
  2. Design a Windows Form with TextBoxes for Employee Number (ENO), Employee Name (EName), and Salary, along with Save and Display buttons.
  3. Create a database table to store employee details.
  4. Establish a connection between the VB.NET application and the database using a connection string.
  5. When the Save button is clicked:
    • Read the values entered in the TextBoxes.
    • Execute an SQL INSERT query to store the employee details into the database.
  6. When the Display button is clicked:
    • Execute an SQL SELECT query to retrieve all employee records.
    • Bind the retrieved data to the GridView control.
  7. Display the employee details in the GridView.
  8. Stop the application.

Source Code (VB.NET)

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\student\Documents\Emp1.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 (ENO, EName, Salary) VALUES (" & TextBox1.Text & ", '" & TextBox2.Text & "', " & TextBox3.Text & ")"
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
        ds.Clear()
        display()
    End Sub

End Class

FAQ Section

Q1. What is the purpose of a GridView control?
A GridView control is used to display data in tabular form, making it easy to view and manage multiple records from a database.

Q2. Which database can be used for this program?
MS Access, SQL Server, or any other supported database can be used with VB.NET.

Q3. Why is a connection string required?
A connection string is needed to establish communication between the VB.NET application and the database.

Q4. Can this program be extended further?
Yes, additional features such as Update, Delete, and Search operations can be added.

Q5. What concepts are learned from this program?
Students learn form design, database connectivity, SQL queries, and data binding using GridView control.

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top