Home All Groups Group Topic Archive Search About

Strongly typed Datasets and DataView

Author
17 Feb 2006 4:27 PM
Vayse
I have two questions on this. I'll show my code first

'**********************************************************
Dim taEvents As New AssetsDataSetTableAdapters.HTEventsTableAdapter
Dim dtEvents As New AssetsDataSet.HTEventsDataTable

taEvents.Fill(dtEvents)

Dim viewEvents As New DataView(dtEvents)
viewEvents.RowFilter = "EventDay Like 'D*'"
viewEvents.Sort = "EventDay ASC"

Dim rowView As DataRowView
Me.txtResult.Clear()
For Each rowView In viewEvents
                Me.txtResult.Text = Me.txtResult.Text & rowView("EventDay")
& ": " & rowView("EventText") & vbCrLf
Next

'**********************************************************

1) Is it possible to use a strongly typed row instead of rowView above?

2) Now lets say I want to make changes as below and write back. Is this
possible using taEvents?

Dim dtFiltered As DataTable = viewEvents.ToTable()
Dim rowEvent As DataRow

            For Each rowEvent In dtFiltered.Rows
                rowEvent("EventText") = Me.txtNewText.Text
            Next

            taEvents.Update(CType(dtFiltered,
AssetsDataSet.HTEventsDataTable))   ' -> Won't work


Thanks
Vayse

Author
18 Feb 2006 8:14 AM
Miha Markic [MVP C#]
Show quote
"Vayse" <vayse@nospam.nospam> wrote in message
news:%23bkkL89MGHA.2628@TK2MSFTNGP15.phx.gbl...
>I have two questions on this. I'll show my code first
>
> '**********************************************************
> Dim taEvents As New AssetsDataSetTableAdapters.HTEventsTableAdapter
> Dim dtEvents As New AssetsDataSet.HTEventsDataTable
>
> taEvents.Fill(dtEvents)
>
> Dim viewEvents As New DataView(dtEvents)
> viewEvents.RowFilter = "EventDay Like 'D*'"
> viewEvents.Sort = "EventDay ASC"
>
> Dim rowView As DataRowView
> Me.txtResult.Clear()
> For Each rowView In viewEvents
>                Me.txtResult.Text = Me.txtResult.Text & rowView("EventDay")
> & ": " & rowView("EventText") & vbCrLf
> Next
>
> '**********************************************************
>
> 1) Is it possible to use a strongly typed row instead of rowView above?

Yes, use DataViewRow.Row property and cast is to strong typed DataRow.

>
> 2) Now lets say I want to make changes as below and write back. Is this
> possible using taEvents?
>
> Dim dtFiltered As DataTable = viewEvents.ToTable()
> Dim rowEvent As DataRow
>
>            For Each rowEvent In dtFiltered.Rows
>                rowEvent("EventText") = Me.txtNewText.Text
>            Next
>
>            taEvents.Update(CType(dtFiltered,
> AssetsDataSet.HTEventsDataTable))   ' -> Won't work

No, casting won't work here because ToTable looses type information.
Instead, you might check if taEvents.Update accepts DataTable or create a
new HTEventsDataTable, merge the dtFiltered into and pass it to Update.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

AddThis Social Bookmark Button