none
DataSet/DataTables and SQLCommand RRS feed

  • Question

  • Hi
    FIrst of all let me describe my situation: I have strong typed DataSet with few DataTables from database + my own DataTable. I have to fill this DataTable with values from other DataTables. My questions are:
     
    1. Is there any way to use SQLCommands (ex. SELECT with INNER JOINs) to fill my created table from those DataSet/DataTables datas??
     
    2. What is the simpliest way to do such kind of filling?
     
    Thanks for any help
     
    Konrad
     
    Thursday, June 21, 2007 2:03 PM

Answers

  • DataTables know nothing of SQL and don't have methods to do SELECTs and JOINs.  There are basically two ways to do what you're trying to do.

    You can write your own select/join code.  You'll iterate through the DataRows in your primary DataTable and do lookups (probably via Filter) on each secondary table, and populate the output DataTable column by column. This has the merit of being something you can do after your DataTables are filled, while disconnected from the database, but it's not much of a merit in my opinion.

    The simplest way to do it is to make the database do the work for you:  create a DataTable whose TableAdapter has a SelectCommand that does the SELECT and JOIN.
    Thursday, June 21, 2007 8:35 PM

All replies

  • DataTables know nothing of SQL and don't have methods to do SELECTs and JOINs.  There are basically two ways to do what you're trying to do.

    You can write your own select/join code.  You'll iterate through the DataRows in your primary DataTable and do lookups (probably via Filter) on each secondary table, and populate the output DataTable column by column. This has the merit of being something you can do after your DataTables are filled, while disconnected from the database, but it's not much of a merit in my opinion.

    The simplest way to do it is to make the database do the work for you:  create a DataTable whose TableAdapter has a SelectCommand that does the SELECT and JOIN.
    Thursday, June 21, 2007 8:35 PM
  • Thanks for answer.
    I think I have to use TableAdapters 'cause each value from my datatable's colum have to be calculate from 2 or 3 another DataTables' columns and simply Filter method can't be useful...
     
    Thanks again!
     
    Konrad
    Thursday, June 21, 2007 10:16 PM