0% found this document useful (0 votes)
22 views3 pages

Update Data Button

update quiry code

Uploaded by

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

Update Data Button

update quiry code

Uploaded by

nilkamal2266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Imports [Link].

OleDb
Public Class Form8

Dim connectionString As String = "Provider=[Link].12.0;Data


Source=C:\Users\nilka\Documents\Visual Studio 2012\Projects\nk pharmacy system
2012\nk pharmacy system 2012\[Link]"

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


LoadDataIntoListView()
End Sub

Private Sub LoadDataIntoListView()


' Configure the ListView
[Link]()
[Link] = [Link]

[Link]("Name", 150, [Link])


[Link]("user id", 100, [Link])
[Link]("password", 100, [Link])
[Link]("role", 100, [Link])

Try
Using connection As New OleDbConnection(connectionString)
[Link]()
Dim query As String = "SELECT firstname,userid,pass,role FROM
table1"
Using command As New OleDbCommand(query, connection)
Using reader As OleDbDataReader = [Link]()
While [Link]()
Dim item As New
ListViewItem(reader("firstname").ToString())

[Link](reader("userid").ToString())
[Link](reader("pass").ToString())
[Link](reader("role").ToString())

[Link](item)
End While
End Using
End Using
End Using
Catch ex As Exception
[Link]("Error: " & [Link])

End Try
End Sub

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs)


Handles [Link]

End Sub

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


[Link]
Dim firstname As String = [Link]
Dim userid As String = [Link]
Dim pass As String = [Link]
Dim role As String = [Link]

If [Link](firstname) OrElse [Link](userid)


OrElse [Link](pass) OrElse [Link](role) Then
[Link]("Please fill in all fields.")
Else
' Call the function to save data to the database
SaveDataToDatabase(firstname, userid, pass, role)
End If

End Sub
Private Sub SaveDataToDatabase(firstname As String, userid As String, pass As
String, role As String)

Dim query As String = "INSERT INTO table1 (firstname,userid,pass,mobile)


VALUES (@name,@id,@pass,@role)"

Using connection As New OleDbConnection(connectionString)

Using command As New OleDbCommand(query, connection)

[Link]("@name", [Link])
[Link]("@id", [Link])
[Link]("@pass", [Link])
[Link]("@role", [Link])

Try
[Link]()
[Link]()
[Link]("Data saved successfully.")

Catch ex As Exception
[Link]("Error: " & [Link])
Finally
[Link]()
End Try
End Using
End Using
End Sub

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

End Sub

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


[Link]
If [Link] = 0 Then
[Link]("Please select a row to edit.", "Information",
[Link], [Link])
Return
End If

Dim selectedItem As ListViewItem = [Link](0)


Dim data As New Dictionary(Of String, String) From {
{"firstname", [Link](0).Text},
{"userid", [Link](1).Text},
{"pass", [Link](2).Text},
{"mobile", [Link](3).Text}
}
Dim editForm As New Form11(Data)
[Link]()

' Refresh the ListView after editing


LoadDataIntoListView()
End Sub
End Class

You might also like