0% found this document useful (0 votes)
10 views5 pages

VB.NET Product Management Code

The provided code is a Visual Basic .NET application for managing product records in a hardware shop database. It allows users to load, add, save, delete, and navigate through product records displayed in a DataGridView. The application handles database connections and operations using SqlConnection and SqlDataAdapter, with error handling for potential exceptions.

Uploaded by

flamepamsrap
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

VB.NET Product Management Code

The provided code is a Visual Basic .NET application for managing product records in a hardware shop database. It allows users to load, add, save, delete, and navigate through product records displayed in a DataGridView. The application handles database connections and operations using SqlConnection and SqlDataAdapter, with error handling for potential exceptions.

Uploaded by

flamepamsrap
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Here's the full code:

Imports [Link]

Public Class Form1

Dim connectionString As String = "Server=(local);Database=TechzoneHardwareShop;Integrated


Security=True;"

Dim connection As New SqlConnection(connectionString)

Dim adapter As SqlDataAdapter

Dim table As New DataTable()

Dim currentIndex As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

Try

[Link]()

adapter = New SqlDataAdapter("SELECT * FROM Products", connection)

Dim builder As New SqlCommandBuilder(adapter)

[Link](table)

[Link] = table

[Link]()

If [Link] > 0 Then

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()

[Link] = [Link](currentIndex)("Price").ToString()

End If

Catch ex As Exception
[Link]("Error: " & [Link])

End Try

End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles [Link]

[Link]([Link], [Link], [Link], [Link])

[Link] = table

currentIndex = [Link] - 1

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()

[Link] = [Link](currentIndex)("Price").ToString()

End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles [Link]

Try

[Link](table)

[Link]("Record saved successfully")

Catch ex As Exception

[Link]("Error: " & [Link])

End Try

End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles [Link]

Try
If currentIndex >= 0 AndAlso currentIndex < [Link] Then

[Link](currentIndex).Delete()

[Link](table)

If [Link] > 0 Then

currentIndex = 0

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()

[Link] = [Link](currentIndex)("Price").ToString()

Else

[Link]()

[Link]()

[Link]()

[Link]()

End If

[Link]("Record deleted successfully")

Else

[Link]("No record to delete")

End If

Catch ex As Exception

[Link]("Error: " & [Link])

End Try

End Sub

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles [Link]


If currentIndex < [Link] - 1 Then

currentIndex += 1

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()

[Link] = [Link](currentIndex)("Price").ToString()

End If

End Sub

Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles [Link]

If currentIndex > 0 Then

currentIndex -= 1

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()

[Link] = [Link](currentIndex)("Price").ToString()

End If

End Sub

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles


[Link]

If [Link] >= 0 Then

currentIndex = [Link]

[Link] = [Link](currentIndex)("ProductID").ToString()

[Link] = [Link](currentIndex)("ProductName").ToString()

[Link] = [Link](currentIndex)("Quantity").ToString()
[Link] = [Link](currentIndex)("Price").ToString()

End If

End Sub

End Class

You might also like