General question re: inserting table programatically

NS_Caver

New member
Joined
Dec 9, 2010
Messages
3
Programming Experience
1-3
Hi All,

I have read and completed several tutorials over the past few days. I feel there is something I'm missing, and it would appear it's quite important for what I'm trying to do. Allow me to briefly explain what it is that I'm trying to do.

I want to create a contact database for an organization. The database should be complemented by a GUI front end. The database should be created and populated programmatically. I want to use MDB as the DB type since it does not require any additional software to be installed.

It would seem like a pretty simple project.

I've learned how to create the database file. I've learned how to read and manipulate a populated database. For the life of me, even though I've tried to work with different code samples, I can't figure out how to insert a table and define fields.

I fear that part of my problem comes from reading too many different types of examples. It would seem that a lot of the code for the actual table design actually works, but it's when I try to connect to the DB that I seem to get the error.

I've searched for many tutorials, but still can't seem to get it to work.

The tutorial I ended up using for DB creation is HERE.

The tutorial I used to learn about working with populated databases is HERE.

Might anyone know of a tutorial or resource I could reference that would help me figure out how to take the database I created in the first tutorial and populate it programmatically to create the database that is being used in tutorial #2?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,742
Location
Sydney, Australia
Programming Experience
10+
Why exactly should the database be created programmatically? Is there a specific reason that you can't just deploy a ready-made database with the app? If you want to be able to create new databases later, it would be easier to embed a ready-made database as a resource and then just extract it and save it to a file whenever needed.

If you really do want to build the database programmatically then you must use ADOX to do so, as you have read. Once the MDB file exists, you can then use ADOX or ADO.NET to build the schema. I would use ADO.NET. In that case, doing so is just like any other ADO.NET. You connect to the database just as you would to retrieve or save data. You create the same OleDbCommand you would to retrieve or save data. You set its CommandText to the appropriate SQL code, e.g. a CREATE TABLE statement, and then call ExecuteNonQuery.
 
Top Bottom