11

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1.Imports System.Data.

OleDb

2. Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|


DataDirectory|\EmployeeDatabase.accdb;"

Dim connection As New OleDbConnection(connectionString)

populate

3. Dim insertQuery As String = "INSERT INTO Employee(ID, Name, Date_Hired, Salary)


VALUES('FT0237', 'FRANCIS K', #3/3/2017#, 450);"

' Add similar INSERT statements for other employees

Try

connection.Open()

Dim command As New OleDbCommand(insertQuery, connection)

command.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show("Error: " & ex.Message)

Finally

connection.Close()

End Try

4.

Dim query As String = "SELECT * FROM Employee WHERE Year(Date_Hired) = 2017;"

' You can change the year as needed

' Execute the query and display the results

Try

connection.Open()

Dim adapter As New OleDbDataAdapter(query, connection)

Dim dataTable As New DataTable

adapter.Fill(dataTable)

' Display the data in a DataGridView or a ListBox

Catch ex As Exception

MessageBox.Show("Error: " & ex.Message)

Finally
connection.Close()

End Try

5.

Dim query As String = "SELECT * FROM Employee WHERE Salary > 250;"

' Execute the query and display the results

Try

connection.Open()

Dim adapter As New OleDbDataAdapter(query, connection)

Dim dataTable As New DataTable

adapter.Fill(dataTable)

' Display the data in a DataGridView or a ListBox

Catch ex As Exception

MessageBox.Show("Error: " & ex.Message)

Finally

connection.Close()

End Try

You might also like