0% found this document useful (0 votes)
16 views9 pages

VB.NET Database Connection and Management

This document contains code for a multi-form VB.NET application that allows users to connect to a database, login, and perform CRUD operations on product data. Form1 handles the database connection. Form2 provides a login form. Form3 acts as a menu to navigate between other forms. Form4 allows adding, updating, deleting, and searching for products in the database.

Uploaded by

robert
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)
16 views9 pages

VB.NET Database Connection and Management

This document contains code for a multi-form VB.NET application that allows users to connect to a database, login, and perform CRUD operations on product data. Form1 handles the database connection. Form2 provides a login form. Form3 acts as a menu to navigate between other forms. Form4 allows adding, updating, deleting, and searching for products in the database.

Uploaded by

robert
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

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link] = "Server=" & [Link] & ";" _

& "User ID=" & [Link] & ";" _

& "Password=" & [Link] & ";" _

& "database=db_gino"

Try

[Link]()

MsgBox("You Are Connected!")

[Link]()

Catch ex As Exception

MsgBox([Link])

End Try

[Link]()

[Link]()

End Sub

End Class
Public Class Form2

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


[Link]

strsql = "SELECT Username, Password FROM tbl_login WHERE Username= @field1


AND Password= @field2"

objcmd = New [Link](strsql, objconn)

With objcmd

.[Link]("@field1", [Link])

.[Link]("@field2", [Link])

End With

[Link]()

[Link]()

objdr = [Link]

If ([Link]()) Then

MsgBox("You Have Successfully Login !")

[Link]()

[Link]()

[Link]()

[Link]()

Else

MsgBox("Error Username or Password !")

End If

[Link]()
[Link]()

End Sub

End Class

Public Class Form3

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

End Sub

End Class
Public Class Form4

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


[Link]

strsql = "INSERT INTO tbl_product (Product,Price) VALUES (@field1,@field2)"

objcmd = New [Link](strsql, objconn)

With objcmd

.[Link]("@field1", [Link])

.[Link]("@field2", [Link])

End With

[Link]()

[Link]()

MsgBox("Record Added!")

[Link]()
Dim ab = MsgBox("Register another one?", vbYesNo)

If ab = vbYes Then

[Link] = ""

[Link] = ""

[Link]()

Else

[Link] = ""

[Link] = ""

End If

End Sub

Sub filllistview()

Try

[Link]()

strsql = "SELECT * FROM tbl_product ORDER BY Product ASC"

objcmd = New [Link](strsql, objconn)

objdr = [Link]

While ([Link]())

With [Link](objdr("Product"))

.[Link](objdr("Price"))

End With

End While

[Link]()

[Link]()

Catch ex As Exception

MsgBox([Link])

[Link]()

End Try

End Sub

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

[Link]()

[Link] = [Link]

End Sub
Private Sub ListView1_MouseClick(sender As Object, e As MouseEventArgs) Handles
[Link]

With [Link](0)

[Link] = .SubItems(0).Text

[Link] = .SubItems(1).Text

End With

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


[Link]

objcmd = [Link]()

[Link] = "UPDATE tbl_product SET Price=@field2 WHERE


Product=@field1"

With objcmd

.[Link]("@field1", [Link])

.[Link]("@field2", [Link])

[Link]()

filllistview()

MsgBox("Update Record!")

[Link] = ""

[Link] = ""

[Link]()

End With

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


[Link]

objcmd = [Link]()

[Link] = "DELETE FROM tbl_product WHERE Product=@field1"

With objcmd

.[Link]("@field1", [Link])

[Link]()

filllistview()

MsgBox("Delete Record!")

[Link] = ""

[Link] = ""
[Link]()

End With

End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles


[Link]

Try

[Link]()

[Link]()

strsql = "SELECT * FROM tbl_product WHERE Product LIKE @field1 '%'"

objcmd = New [Link](strsql, objconn)

With objcmd

.[Link]("@field1", [Link])

End With

objdr = [Link]

While ([Link]())

With [Link](objdr("Product"))

.[Link](objdr("Price"))

End With

End While

[Link]()

[Link]()

Catch ex As Exception

MsgBox([Link])

[Link]()

End Try

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


[Link]

[Link]()

[Link]()

End Sub
End Class

You might also like