connecting to, and updating a relational database

Saeros3

Member
Joined
Aug 19, 2009
Messages
9
Programming Experience
1-3
ok, so i have a database with 2 related tables (one-to-many). What i'm trying to do is to connect to the database, fill 2 DataTable objects, and add them to a DataSet object. Then I would need to bind each column in the DataTables to a text box on the form, and allow the user to update the database after modification. They will also need to be able to add/remove a record to/from the db.
However, I'm not quite sure how to do all of this. I'll write some specific questions below:

- will i need a new DataAdpater for each table?

- Will visual basic automatically enforce referential integrity between the 2 related tables in the database? if not, how do i do that?

- I read somewhere that it's easier to update a database with a OleDbCommandBuilder object, does anyone know of any examples of that?

Also, if i'm going about this completely wrong, feel free to suggest a better (or more accurate) way of doing it.
 
Last edited:
- will i need a new DataAdpater for each table?
Yes you will.
- Will visual basic automatically enforce referential integrity between the 2 related tables in the database? if not, how do i do that?
Yes, as long as you propagate that relationship to your VB data store. Just as you have a database containing two tables with a foreign key relation between them, so you will have a DataSet containing two DataTables with a DataRelation between them in your VB app.
- I read somewhere that it's easier to update a database with a OleDbCommandBuilder object, does anyone know of any examples of that?
Yes, using the command builder means that you don't have to write all the SQL code yourself or create your own parameters. There are a few caveats and limitations with command builders though.

You can use the Data Source wizard in VS to generate a typed DataSet if you like. This will create classes for the DataSet, DataTables, DataRelations and TableAdapters for you based on the schema of your database. This like command builders on steroids. The TableAdapters encapsulate the connections, commands and data adapters. This is the easiest way to go but you may learn more if you work closer to the metal yourself.

There are various links in my signature that you may find useful, including some of the videos.
 
thanks :)

hi jmcilhinney,
thanks for your reply.
I just have a few questions, though, if you don't mind answering them:

- do you have any more info on DataRelations? maybe some code samples?
- since i need 2 DataAdapters, will i need 2 CommandBuilder objects (1 for each DataAdapter)? or have i just completely missed the point?

I'm sorry for being so difficult, but any information would be appreciated.
 
- do you have any more info on DataRelations? maybe some code samples?
What efforts have you made to find information for yourself? The MSDN Library provides tons of information on .NET development and there's a whole WWW out there. Look first, ask questions later.
- since i need 2 DataAdapters, will i need 2 CommandBuilder objects (1 for each DataAdapter)?
When you create a command builder you pass a data adapter as an argument. As you say, two data adapters means two command builders.
 
Back
Top