开发者

Adding a datatable and a session containing datatable

开发者 https://www.devze.com 2022-12-19 04:30 出处:网络
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?

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开发者_JAVA百科 add these two, so how can I do this?


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


in C#:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消