Here's the updated code that uses MySQL instead of SQL Server:
Imports [Link]
Public Class Form1
Dim connectionString As String = "Server=localhost;Port=3306;Database=Hardware;User
Id=root;Password=mditbaihm2006;"
Dim connection As New MySqlConnection(connectionString)
Dim adapter As MySqlDataAdapter
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 MySqlDataAdapter("SELECT * FROM Products", connection)
Dim builder As New MySqlCommandBuilder(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]()
[Link](table)
[Link]()
[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]()
[Link](table)
[Link]()
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()
txtPrice