Link to home
Start Free TrialLog in
Avatar of MedSouth
MedSouth

asked on

A Simple Database Example

DB Guru's:

    I have put together a small DB example that I would like some help with.  I know that most of what I put on the form isn't needed anymore but I need to understand the basics for navigating a DB.  Also I have not put a datareader or anything on the form.  This way I can see the differances from sql express and compact (hopefully I will get a example from each).  
Public Class Form1
 
    Public MaxRecNo As Integer        'Max Number of Records in the DB
    Public RecNo As Integer           'Current Record Number
 
    Private Sub btnClearForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearForm.Click
        'Clears the fields on the form.  
        tbName.Text = ""
        tbAge.Text = ""
        dtpDOB.Text = ""
        cbVerified.Checked = False
    End Sub
 
    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        'Adds a new record to the DB with the fields Provided
        db.AddRecord()
        db.Name.Text = tbName.Text
        db.Age.Text = tbAge.Text
        db.DOB.Text = dtpDOB.Text
        db.Verified = cbVerified.Checked
        MaxRecNo = +1
        RecNo = MaxRecNo
    End Sub
    Private Sub btnBackOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackOne.Click
        'Backup 1 record and displays the contents in the fields
        If RecNo - 1 < 1 Then RecNo = 1 Else RecNo = -1
        updatefields()
 
    End Sub
 
    Private Sub btnForwardOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForwardOne.Click
        'Forward 1 record and display the contents in the fields
        If RecNo + 1 > MaxRecNo Then RecNo = MaxRecNo Else RecNo = +1
        updatefields()
 
    End Sub
 
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        'Updates the current Record.
        db(RecNo).Name.Text = tbName.Text
        db(RecNo).Age.Text = tbAge.Text
        db(RecNo).DOB.Text = dtpDOB.Text
        db(RecNo).Verified = cbVerified.Checked
 
    End Sub
 
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        'Deletes current record
        db(RecNo).Delete()
        If RecNo - 1 < 1 Then RecNo = 1 Else RecNo = -1
        updatefields()
 
    End Sub
 
    Private Sub btnListNonVerified_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListNonVerified.Click
        'Displays all non verified records in the DB and displayes then in the RichTextBox.
        'I would prefer not to use a RichTextBox but a DataGrid or the like to display the records.
        Dim I As Integer
        For I = 1 To MaxRecNo
            If db(I).Verified = False Then      '
                '    'add record to DataGrid view    '  I know this can be done with a select statement just not how to add it to the Control.
            End If                            '
        Next
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'MaxRecNo = db.MaxRecords 'Initialize to contain the # of records in the DB
        RecNo = 0  ' or 1  does recordsets start at 0 or 1?
    End Sub
 
    Private Sub updatefields()
        tbName.Text = db(RecNo).Name.Text
        tbAge.Text = db(RecNo).Age.Text
        dtpDOB.Text = db(RecNo).DOB.Text
        cbVerified.Checked = db(RecNo).Verified
 
    End Sub
End Class

Open in new window

SampleDB.bmp
Avatar of MedSouth
MedSouth

ASKER

Forgot to add I would also like to have a large field that would accept a stream or file as it's data.

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help the binding source and navigator makes things alot easier.