Joining data from a local datatable and a database table

Hello all,

I have this problem:

I need to get data from a table giving some parameters. The parameter list can be very long, like this:
[code]
string SelectStatement = "select unidade, numero, date " +
"from _dsa_ihs_table " +
"where unidade in ('1234', '1235', '1236', '1237', ..., '9999') " +
"order by unidade" ;
[/code]

I can create another datatable with the parameter list i need, like this:
[code]
DataTable dt = new DataTable("Table1");
dt.Columns.Add("unidade");
DataRow dr = dt.NewRow();
dr["unidade"]= "1234";
dt.Rows.Add(dr);
dt.AcceptChanges();
.
.
.
dr["unidade"]= "9999";
dt.Rows.Add(dr);
dt.AcceptChanges();
[/code]

My problem is i don't know how to join the 2 datatables, the one in the database and that i've created manualy.

Does anyone have the answer?

Thank you,
Joaquim

Comments

  • Re:
    Simple,
    Dataset is use for such purpose only.Just use adapter and data set.Load every table from database to data set.Now u have 2 table in dataset.1st ur manually created table and 2nd datatable which u have created[writing code].
    Now,you need to link both this datatable.Table are always link by having common column in both table.Here,u hav to satisfy some .NET condition.
    1 : linking in both table require same domain of column and same type of column.

    Here, u have 2 datatable in data set.Now do coding as per ur requirement.As i u hav not mention any requirement in this section.

    Remain alert that you cannot create new table in database from ur code.As this you hav to manually perform in database iteself.Ya, u can add,delete or update records in already created table.

    ok,hop u hav solve ur some wht query.
    Regards
    Chintan Desai.
    http://www.visharadsoft.com
    India
  • Thank you Chintan,

    But what i realy want to know is the syntax to do that.

    Can i do something like:

    string SelectStatement = "select a.unidade, b.nome, a.numero, a.date " +
    "from _dsa_ihs_table a, test b " +
    "where a.unidade = b.unidade";

    Where: _dsa_ihs_table is a table from the database and test is a memory Datatable? Or where both tables are memor DataTables stored in the Dataset?

    Joaquim


    : Re:
    : Simple,
    : Dataset is use for such purpose only.Just use adapter and data
    : set.Load every table from database to data set.Now u have 2 table in
    : dataset.1st ur manually created table and 2nd datatable which u
    : have created[writing code].
    : Now,you need to link both this datatable.Table are always link by
    : having common column in both table.Here,u hav to satisfy some .NET
    : condition.
    : 1 : linking in both table require same domain of column and same
    : type of column.
    :
    : Here, u have 2 datatable in data set.Now do coding as per ur
    : requirement.As i u hav not mention any requirement in this section.
    :
    : Remain alert that you cannot create new table in database from ur
    : code.As this you hav to manually perform in database iteself.Ya, u
    : can add,delete or update records in already created table.
    :
    : ok,hop u hav solve ur some wht query.
    : Regards
    : Chintan Desai.
    : http://www.visharadsoft.com
    : India

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories