CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2002
    Posts
    11

    create a new database in VB .NET how?

    how do you create a 'new' database with only code in vb .net. I can connect to an existing database and fill a datagrid with its contents. Is it much different than that? I am assuming that after creation is when you would need to add more rows etc.

    Or how about this, since the databases are going to be almost virtually the same, is there a way to copy a database with code and than erase not the rows or columns but just the data in the cells themselves?
    Last edited by proKrastinate; December 15th, 2002 at 12:32 AM.

  2. #2
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    cat = New ADOX.Catalog()

    cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & file_name & ";")



    'then add your tables as needed

    dim tbl as new adox.table

    tbl.name ="table_name"

    'add your columns as needed

    tbl.Columns.Append("column_name", ADODB.DataTypeEnum.adSingle)

    'append your catalog (dimmed as cat) to add the new table (dimmed as tbl)

    cat.Tables.Append(tbl)

    'to add more tables start with "dim tbl as new adox.table"

  3. #3
    Join Date
    Dec 2002
    Posts
    11
    thankx for getting me on the right track. I figured out that I needed to add a reference to ADOX and do an imports statement to use your code. Thx again

  4. #4
    Join Date
    Dec 2002
    Posts
    11
    one other thing, is it necessary to add this to the end of the oCat.Create

    "Jet OLEDB:Engine Type=5")

    what does it do?

  5. #5
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    I use the code exactly how I showed it to you

  6. #6
    Join Date
    Dec 2002
    Posts
    11
    mine wouldn't work that way. It kept saying that adox.catalog was unidentified. but now that i did what was posted above, it seems to work without errors. Haven't tested it yet because my program is still sorting out some stuff before i can check to see whether it creates the db or not.

  7. #7
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    did you add adox to your project ?

  8. #8
    Join Date
    Dec 2002
    Posts
    11
    do you mean with an imports statement? if so, than yes, but it would only be recognized after i made the reference. before it would only recognize 'Microsoft' 'System' and "i think the name of my proj' to the imports available list that automatically comes up when you type Imports. after addding the reference the ADOX was able to be imported.

    Don't know if this matters but im using only vb .net and not the entire visual studio .net.

  9. #9
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    Yes in your solutions explorer under references you need to see BOTH adodb and adox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured