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