0% found this document useful (0 votes)
2 views2 pages

Admin Page

The document is a code snippet for an admin page in a Visual Basic application that connects to a SQL Server database to manage bookings. It includes methods to load booking data into a DataGridView, navigate to other forms, and delete selected bookings with confirmation. Error handling is implemented for database operations to ensure user-friendly feedback.

Uploaded by

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

Admin Page

The document is a code snippet for an admin page in a Visual Basic application that connects to a SQL Server database to manage bookings. It includes methods to load booking data into a DataGridView, navigate to other forms, and delete selected bookings with confirmation. Error handling is implemented for database operations to ensure user-friendly feedback.

Uploaded by

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

ADMIN PAGE

Imports System.Data.SqlClient

Public Class adimnpage


Dim connectionString As String = "Data Source=RB-REALME\SQLEXPRESS03;Initial
Catalog=starlight;Integrated Security=True"
Private Sub LoadData()

Try
Using conn As New SqlConnection(connectionString)
Dim query As String = "SELECT * FROM Booking"
Dim adapter As New SqlDataAdapter(query conn)
Dim table As New DataTable()
adapter.Fill(table)
dgvbooking.DataSource = table
End Using
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub

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


btnLoadData.Click
LoadData()
End Sub

Private Sub Button3_Click(sender As Object e As EventArgs) Handles Button3.Click


Form2.Show()
Me.Hide()
End Sub

Private Sub Button2_Click(sender As Object e As EventArgs) Handles Button2.Click


Form1.Show()
Me.Hide()
End Sub

Private Sub Button1_Click_1(sender As Object e As EventArgs) Handles


Button1.Click
bookings.Show()
Me.Hide()
End Sub

1
Private Sub dgvbooking_CellContentClick(sender As Object e As
DataGridViewCellEventArgs) Handles dgvbooking.CellContentClick

End Sub
Private Sub DeleteSelectedBooking()
If dgvbooking.SelectedRows.Count > 0 Then
Dim autoId As Integer = dgvbooking.SelectedRows(0).Cells("autoId").Value

Dim result As DialogResult = MessageBox.Show("Are you sure you want to delete


this booking?" "Confirm Delete" MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Try
Using conn As New SqlConnection(connectionString)
conn.Open()
Dim query As String = "DELETE FROM Booking WHERE autoId = @autoId"
Using cmd As New SqlCommand(query conn)
cmd.Parameters.AddWithValue("@autoId" autoId)
cmd.ExecuteNonQuery()
End Using
End Using
MessageBox.Show("Booking deleted successfully.")
LoadData()
Catch ex As Exception
MessageBox.Show("Error deleting booking: " & ex.Message)
End Try
End If
Else
MessageBox.Show("Please select a booking to delete.")
End If
End Sub

Private Sub btnDelete_Click(sender As Object e As EventArgs) Handles


btnDelete.Click
DeleteSelectedBooking()
End Sub
End Class

You might also like