How to get multiple tables into a dataset

  • Thread starter Thread starter Reddy
  • Start date Start date
R

Reddy

Hi,

I have this situation where I need to prepopulate a form(drop down menus)
with data from multiple tables in a database. How do I get multiple tables
within a dataset so that I can acheive this? Any example code would be very
helpful.

Thanks,

Reddy
 
I have this situation where I need to prepopulate a form(drop down menus)
with data from multiple tables in a database. How do I get multiple tables
within a dataset so that I can acheive this? Any example code would be very
helpful.

Hi! If you have a DataSet with multiple tables this is done easily.

1. Create a strongly typed DataSet (from your DB), just drag the tables you
need onto the form.
2. Right-click the sqlconnection (or whatever connection) you have and
choose "Generate DataSet".
3. Now add all the tables you want to the new dataset.
4. Choose to have an instance of this new strongly typed dataset added to
your form.
5. Use the DataSource property on your combobox along with ValueMember and
DisplayMember.

Example:

If you have a table named Orders, and one named Customers, you could list
these in two combos.

combo1.DataSource = YourDataSet.Orders;
combo1.ValueMember = YourDataSet.Orders.OrderIDColumn;
combo1.DisplayMember = YourDataSet.Orders.OrderIDColumn;

combo2.DataSource = YourDataSet.Customers;
combo2.ValueMember = YourDataSet.Customers.CustomerIDColumn;
combo2.DisplayMember = YourDataSet.Customers.FullNameColumn;
 
I am new to ADO.NET . Can you please tell me how to,
Create a DataSet with multiple tables,

1. Use the Server Exploreer window (Menu: View -> Server Explorer) and find
your database-server.
2. From there choose SQL Servers and then find your database.
3. Open the database Tables entry and drag the tables you want from the list
onto your Form.
4. Now you will have one sqlConnection object on your form (yellow bottom
screen) and one sqlDataAdapter for each table you've dragged over.
5. Use Generate DataSet (Menu: Data -> Generate DataSet).
6. Here the dialog will automatically select all the tables you've dragged
into the form, if not, select the desired tables.
7. Name the dataset something (MyDataSet) and
8. Let the "Add this dataset to the designer" be checked.

....Now you have your typed dataset up and running.
Again if you can highlight it with some code that would be great

I cannot give you any code since this is a design-time auto-generate
operation.
 
Back
Top