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

MySQL Product Management Code

The document contains updated Visual Basic code that connects to a MySQL database to manage product records. It includes functionalities for loading, adding, saving, deleting, and navigating through product entries in a DataGridView. Error handling is implemented to manage exceptions during database operations.

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)
8 views5 pages

MySQL Product Management Code

The document contains updated Visual Basic code that connects to a MySQL database to manage product records. It includes functionalities for loading, adding, saving, deleting, and navigating through product entries in a DataGridView. Error handling is implemented to manage exceptions during database operations.

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 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

You might also like