views:

164

answers:

3

I have a session which contains a datatable and also have a function which returns a datatable. I need to add these two. How can I do this?

The below code is to be replaced with correct code.

Session("Table")=Session("Table")+obj.GetCustomer()

...where obj is an object of the business layer.

The '+' sign cannot be used to add these two, so how can I do this?

A: 

Hi,

if the two tables are identical (columns, etc) you might want to go through all rows of one trable and append them to the other one. For convenience you could use an extension method. Maybe there's a more elegant version, but that's a first thought.

-sa

Sascha
+2  A: 

I would try something like this:

Dim MyDataSet1 As New DataSet()
Dim MyDataSet2 As New DataSet()

Dim dt1 As New DataTable() = ctype(Session("Table"), DataTable)
Dim dt2 As New DataTable() = obj.GetCustomer()

MyDataSet1.Tables.Add(dt1)
MyDataSet2.Tables.Add(dt2)

MyDataSet1.Merge(MyDataSet2)

Session("Table") = MyDataSet1.Tables(0)

Chris

Chris
Thanks @Chris.Your answer simplified my life
Nandini
+1  A: 

in C#:

Session["Table"] = ((DataSet)Session["Table"]).Merge(obj.GetCustomer());

Daniel Brink