Hello :)
I'm working a project for class that involves a database connection. I have an Acess database called "Libraries" that contains two tables called Libraries and Books. I have to create a form that has two DataGridViews(one that contains the Libraries and their ID #'s, the other that has the media from the selected library). I have to be able to save changes made to the database. There are also two listboxes. One has the types of media (book, DVD, etc). The user can select a media type and the second box will show the items from all libraries that are that type of media. I'm really stuck on how to go about this, but I have some pieces of code. Would someone be willing to help walk me through this?
I have the form and the database connection done. This is the first part that I have:
Dim connstr As String = "Provider=Microsoft.ACE.OLEBD.12.0;Data Source=C:\Libraries.accdb"
Dim Shareddt As New DataTable()
Dim sqlStr As String = "SELECT * FROM Libraries"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connstr)
I also have a sub to fill the list box with the types of media:
Sub populateListBoxWithMedia()
lstMediaType.Items.Clear()
Dim strSQL As String = "SELECT DISTICT Media Type FROM Libraries"
Dim dt As New DataTable()
Dim dataAdapter As New OleDb.OleDbDataAdapter(strSQL, connstr)
dataAdapter.Fill(dt)
lstMediaType.DataSource = dt
For i As Integer = 0 To (dt.Rows.Count - 1)
lstMediaType.Items.Add(dt.Rows(i)("Media Type"))
Next
dataAdapter.Dispose()
lstMediaType.SelectedIndex = 0
End Sub
And I have the save changes button:
Private Sub btnSaveChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveChanges.Click
Dim strSQL As String
Dim dataAdapter As New OleDb.OleDbDataAdapter(strSQL, connstr)
Dim commandBuilder As New OleDb.OleDbCommandBuilder(dataAdapter)
Dim changes As Integer
changes = dataAdapter.Update(Shareddt)
dataAdapter.Dispose()
MsgBox("Changes saved to database!")
End Sub
Nothing shows up when I run the form. Any ideas?
Thank you in advance!