0

Hi, I've been having issues with this for the last 4 hours and I don't know what to do. Basically I'm using an MS Access database to store information on a movie collection, however I do NOT want to use the crappy controls microsoft has for populating and navigating databases, namely MS ACCESS ones (the controls that have the pre-made toolbar and the save crap). So I've designed my own. Here is a screenshot of what it looks like (don't judge me on the movies, it's not my movie collection I'm doing this for a project for my friend):

http://img708.imageshack.us/img708/4570/egimovcat.png

So what I have it do so far, is when you click on a record in the DataGridView, it populates the form below and further on allows for editing and updating. ID being the primary key.

My problem: I have no clue how to make the update buttons to update the record selected / presented in the fields. I also wanted it so I could make a new record by filling out the form, and hitting the new button. I want it so it can delete the selected / presented record (namely basing it off the id field, such as 1 or 2).

My code so far:

Public Class GouldCatalog
    Dim inc As New Integer
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Private Sub AddRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Documents and Settings\Eric\My Documents\Visual Studio 2010\Projects\EGI Movie Catalog\EGI Movie Catalog\db1.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        MsgBox("Database connection successful!", MsgBoxStyle.Information, "Connection Established!")
        Sql = "SELECT * from EGIDB"
        da = New OleDb.OleDbDataAdapter(Sql, con)
        da.Fill(ds, "EGIDB")
        dgmain.DataSource = ds.Tables("EGIDB")
    End Sub
    Private Sub chkconfirm_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkconfirm.CheckedChanged
        If chkconfirm.Checked = True Then
            btnupdate.Enabled = True
        ElseIf chkconfirm.Checked = False Then
            btnupdate.Enabled = False
        End If
    End Sub
    Private Sub dgmain_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgmain.CellContentClick
        tbid.Text = dgmain.SelectedCells(0).Value
        tbname.Text = dgmain.SelectedCells(1).Value
        tbyear.Text = dgmain.SelectedCells(2).Value
        tbdescrip.Text = dgmain.SelectedCells(3).Value
        tbrating.Text = dgmain.SelectedCells(4).Value
        If dgmain.SelectedCells(5).Value = 0 Then
            cbloaned.Checked = False
        Else
            cbloaned.Checked = True
        End If
        cbloc.Text = dgmain.SelectedCells(6).Value
        tblocid.Text = dgmain.SelectedCells(7).Value
        tbloaned.Text = dgmain.SelectedCells(8).Value
        tbgenre.Text = dgmain.SelectedCells(9).Value
    End Sub

    Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        ds.Tables("EGIDB").Rows(inc).Item(1) = tbname.Text
        ds.Tables("EGIDB").Rows(inc).Item(2) = tbyear.Text
        da.Update(ds, "EGIDB")
        MsgBox("Successfully updated!", MsgBoxStyle.Information, "Updated!")
    End Sub

    Private Sub btnreconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreconnect.Click
        con.Close()
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Documents and Settings\Eric\My Documents\Visual Studio 2010\Projects\EGI Movie Catalog\EGI Movie Catalog\db1.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        MsgBox("Database connection successful!", MsgBoxStyle.Information, "Connection Established!")
        sql = "SELECT * from EGIDB"
        da = New OleDb.OleDbDataAdapter(sql, con)
        dgmain.DataSource = ds.Tables("EGIDB")
    End Sub
End Class
2
Contributors
1
Reply
18
Views
6 Years
Discussion Span
Last Post by ShahanDev
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.