5 pts.
 Tables, queries, and database with Visual Basic 6
hi i am developing a visual basic application with (vb6.0)and have the following questions,1. how will i add a table in my application and then use one column to be getting data from another table. 2. can i make a query in .mdb and then run it in visual basic.how will i do it if its possible, i have connected to my database (using data environment)and i cant navigate the records.

Software/Hardware used:
ASKED: March 21, 2009  11:11 AM
UPDATED: March 25, 2009  2:06 AM

Answer Wiki:
1) <b>Usually</b>, you add tables to your database at design time, not at runtime from the application. You can read and insert/update data into the database with SQL. 2) Are you using Access ? what version ? are you getting some error when trying to navigate the records ?
Last Wiki Answer Submitted:  March 23, 2009  1:50 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

In general, this is how you create a database in code:

'Define some variables:
    Dim CatDBTest As Database
    Dim CatDBTableDefCategory As TableDef
    Dim CatIdx As Index
    Dim msgCancel As String

    Set CatDBTest = CreateDatabase({catalog name}, dbLangGeneral)   'create the actual MDB file

'Create a table:
    Set CatDBTableDefCategory = CatDBTest.CreateTableDef("Category")
        With CatDBTableDefCategory
            .Fields.Append .CreateField("Category", dbText)
        End With

    CatDBTest.TableDefs.Append CatDBTableDefCategory

'Create a key:
    With CatDBTableDefCategory
        Set CatIdx = .CreateIndex("Key")
        CatIdx.Fields.Append CatIdx.CreateField("Category")
        CatIdx.Primary = True
        .Indexes.Append CatIdx
        .Indexes.Refresh
    End With

That should be enough to get you started.

As for queries, it is easier to create the query in VB and run it using SQL. (IMHO)

 1,410 pts.