|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Strongly typed Datasets and DataView'********************************************************** 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
Show quote
"Vayse" <vayse@nospam.nospam> wrote in message Yes, use DataViewRow.Row property and cast is to strong typed DataRow.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? > No, casting won't work here because ToTable looses type information. > 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 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/ |
|||||||||||||||||||||||