Link to home
Start Free TrialLog in
Avatar of marusha
marusha

asked on

need example of simple database program

i need demo project that is a simple database program
for example it must have these fields - name, age, email
i also need the data shown in a listview control
i should understand it, possibli with descriptions of the things made
the price is good for this
ASKER CERTIFIED SOLUTION
Avatar of vmano
vmano

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
Avatar of marusha
marusha

ASKER

ok... i am waiting
i am not newbie to VB, i just wanted to let you know
OK. Here is how you create an access data base from your VB code.
From your Project/References, check the reference for
Microsot DAO 2.5/3.0 Compatibility library.

here is the code for creating the data base and some records.
    Dim DB      As Database
    Dim TD      As TableDef
    Dim FD      As Field
    Dim RS      As Recordset
    Dim i       As Integer
   
    'Create the database, if you don't have one.
    Set DB = CreateDatabase("C:\test.mdb", dbLangGeneral)
    'Create the table in  that database
    Set TD = DB.CreateTableDef("Table1")
   
    'Now define the fields Name, Age and EMail as text fields.
    Set FD = TD.CreateField("Name", dbText)
    'this will append the fields in the table
    TD.Fields.Append FD
   
    Set FD = TD.CreateField("Age", dbText)
    TD.Fields.Append FD
   
    Set FD = TD.CreateField("EMail", dbText)
    TD.Fields.Append FD
   
    'Now append the Table to the Database
    DB.TableDefs.Append TD
   
    'Now that the database has fields,
    'add some records through a recordset
   
    Set RS = DB.OpenRecordset("Table1", dbOpenTable)
   
    For i = 1 To 5      'Add five records
        RS.AddNew       'Add a new record
       
        RS!Name = "Name" & i
        RS!Age = "Age" & i
        RS!email = "EMail" & i
       
        RS.Update
    Next i
 
    'Close both the recordset and database
    RS.Close
    DB.Close


if you don't understand anything, post a comment.
wait for my next comment to show the data in a list box control
OK. Here is the code to show it in a listbox.

    Dim DB      As Database
    Dim RS      As Recordset
    Dim rcount  As Integer
    Dim i       As Integer
   
    Set DB = OpenDatabase("C:\Test.mdb")
    Set RS = DB.OpenRecordset("SELECT * FROM Table1;")
    List1.Clear
   
    RS.MoveLast
    rcount = RS.RecordCount
    RS.MoveFirst
       
    For i = 0 To rcount - 1
        List1.AddItem RS!Name & "-" & RS!age & "-" & RS!email
    Next i
   
    RS.Close
    DB.Close

let me know if this helps,
vmano.
Avatar of marusha

ASKER

ok
this works fine
i need something more and i'll pay you
i can pay you 400 if you really help me further , not kiddin
so
i want an element in my form (i don't know it's name, it may be this listbox) that aligns the data in the database in columns like Explorer does with the files, sizes, dates and so on
how to make this columns and when clicked a column header it aligns the data by date, by email , by name and so on

i am waiting
if you can't answer PLEASE tell me
don't stop commenting, please, i need you vmano

marusha

P.S. i am a 18 year blonde girl for your information
Use a listview control instead of the listbox. It is part of the windows common controls and allows you to sort easily.
To make it look like explorer you need to set the view property to lvwReport.

You can setup the columns at design time or runtime whichever you prefer.

The code to do it at runtime is:


    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Add 1, "Name", "Name", 1000
    ListView1.ColumnHeaders.Add 2, "Age", "Age", 1000
    ListView1.ColumnHeaders.Add 3, "Email", "Email", 2000



To add the data to the listview:

Dim newListItem As ListItem

    ListView1.ListItems.Clear
    For i = 0 To rcount - 1
       Set newListItem = ListView1.ListItems.Add(, RS!Name, RS!Name)
       newListItem.SubItems(1) = RS!Age
       newListItem.SubItems(2) = RS!Email
    Next i
    Set newListItem = Nothing    


To sort the data on columns:

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    With ListView1
        If .Sorted And .SortKey = ColumnHeader.Index - 1 Then
            If .SortOrder = lvwAscending Then
                .SortOrder = lvwDescending
            Else
                .SortOrder = lvwAscending
            End If
        Else
            .SortOrder = lvwAscending
            .SortKey = ColumnHeader.Index - 1
            .Sorted = True
        End If
    End With
End Sub

mrusha,
According to your actual question you just asked me about a simple DB program and to show the data in a listbox control. i did that. now give me the points. coming to your next question, please post another question and i am sure i will answer it.
thanks,
vmano

I think I've answered the second question, unless marusha has an objection to using a listview control (which is a much nicer control than the standard listbox).

I should have mentioned that the code for sorting the data sorts in ascending order when you first click on the Column Header, and in descending order if you click on it again.

marusha: Have I answered your second question?
Avatar of marusha

ASKER

ok vmano i am paying you
as for the sjrl's answer i want to pay you too
i'll post another question and you'll copy and paste and i'll pay you too (200 points of course)
i'll post the question under 'marusia' nick