Problems with CopytoDataTable() after a query in linq

I

Ivan

Hi,

I've got a problem with a query I make using Linq. The problem is that I
want to show the results in a DataGridView. Until now I had used it without
problems using CopytoDataTable(), but this time this method is not
appliable, it doesn't exist as a method for this query...

This is the code from the query
*******************************************
Dim Source= ds.Tables(0).AsEnumerable()
Dim Change = ds.Tables(1).AsEnumerable()

Dim query = _
From f In Source _
Group Join c In Change On _
f.Field(Of String)("Name") Equals c.Field(Of String)("Name") _
Into children = Group _
From child In children.DefaultIfEmpty() _
Select New With _
{ _
..Order = f.Field(Of Integer)("Order"), _
..Name = f.Field(Of String)("Name"), _
..FPosition = f.Field(Of String)("Position"), _
..cPosition = child.Field(Of String)("Position") _
}

DataGridView1.DataSource = query.CopytoDataTable()??**

************************************************
**Here is where it fails. Until now, with easier queries, i could apply this
method, but this time it seems as it's not implemented...

CAN ANYBODY HELP MEEEEEEE!!??

Thanks in advance!
 
M

Michel Posseth [MCP]

Hello Ivan ,


This is a copy paste from one of my reall life projects

<SNIP>
Private Sub FilterOnDgvObject(ByVal ObjectNr As Decimal)

Me.Cursor = Cursors.WaitCursor

Try

LastSelObjNr = ObjectNr

If ObjectNr < 0 Then

Dim Datarows() As DsRadioMeters.GetRadioMeterErrorsRow =
Me.DsRadioMeters.GetRadioMeterErrors.ToArray

FilterOnBitFields(Datarows)

Else

Dim ObjectVal = From e In DsRadioMeters.GetRadioMeterErrors Select e Where _

e.ObjectNr = ObjectNr

FilterOnBitFields(ObjectVal.ToArray)

End If

Catch ex As Exception

MessageBox.Show(ex.ToString, "~Error ", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Finally

Me.Cursor = Cursors.Default

End Try

End Sub

Private Sub FilterOnBitFields(ByVal DataRows() As
DsRadioMeters.GetRadioMeterErrorsRow)

Me.Cursor = Cursors.WaitCursor

Dim Wo As Nullable(Of Boolean)

If RbtnWOJa.Checked Then

Wo = True

ElseIf RbtnWONee.Checked Then

Wo = False

End If

Dim Stand As Nullable(Of Boolean)

If RbtnStndJa.Checked Then

Stand = True

ElseIf RbtnStndNee.Checked Then

Stand = False

End If

If Wo.HasValue Then

Dim ObjectvalA = From e In DataRows Select e Where _

e.WO = Wo.Value

DataRows = ObjectvalA.ToArray

End If

If Stand.HasValue Then

Dim ObjectValB = From e In DataRows Select e Where _

e.Stand = Stand.Value

DataRows = ObjectValB.ToArray

End If

If Not String.Equals(CmbxErr.SelectedValue, "Alle") Then

Dim ObjectValsC = From e In DataRows Select e Where _

e.ErrMsgs.Contains(CmbxErr.SelectedValue.ToString)

'Dit kan dus ook

'' e.ErrMsgs Like String.Concat("*", CmbxErr.SelectedValue, "*")

DataRows = ObjectValsC.ToArray

End If

Me.txtbxFilter.Text = DataRows.Count.ToString



Me.GetRadioMeterErrorsBindingSource.DataSource = DataRows

End Sub

</SNIP>

Me.DsRadioMeters is the dataset wich is filled on program startup , with the
definition of this dataset i have setup all my databound controls ( in this
case 2 datagrids and 1 combobox )
as the GetRadioMeterErrors might contain hundreds of rows ( mostly 700 + _ )
i have made several filters that may be used in LINQ the application is
lightning fast

so i just rebind the datarows ( datarow array ) to the BindingSource if
the user removes the filter i just rebind the original dataset this works
great for me and i can use the designer to setup my datagridview .

HTH

And regards

Michel Posseth [MCP]
http://www.linkedin.com/in/michelposseth
 
I

Ivan

Thanks! I'll try it

Michel Posseth said:
Hello Ivan ,


This is a copy paste from one of my reall life projects

<SNIP>
Private Sub FilterOnDgvObject(ByVal ObjectNr As Decimal)

Me.Cursor = Cursors.WaitCursor

Try

LastSelObjNr = ObjectNr

If ObjectNr < 0 Then

Dim Datarows() As DsRadioMeters.GetRadioMeterErrorsRow =
Me.DsRadioMeters.GetRadioMeterErrors.ToArray

FilterOnBitFields(Datarows)

Else

Dim ObjectVal = From e In DsRadioMeters.GetRadioMeterErrors Select e Where
_

e.ObjectNr = ObjectNr

FilterOnBitFields(ObjectVal.ToArray)

End If

Catch ex As Exception

MessageBox.Show(ex.ToString, "~Error ", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Finally

Me.Cursor = Cursors.Default

End Try

End Sub

Private Sub FilterOnBitFields(ByVal DataRows() As
DsRadioMeters.GetRadioMeterErrorsRow)

Me.Cursor = Cursors.WaitCursor

Dim Wo As Nullable(Of Boolean)

If RbtnWOJa.Checked Then

Wo = True

ElseIf RbtnWONee.Checked Then

Wo = False

End If

Dim Stand As Nullable(Of Boolean)

If RbtnStndJa.Checked Then

Stand = True

ElseIf RbtnStndNee.Checked Then

Stand = False

End If

If Wo.HasValue Then

Dim ObjectvalA = From e In DataRows Select e Where _

e.WO = Wo.Value

DataRows = ObjectvalA.ToArray

End If

If Stand.HasValue Then

Dim ObjectValB = From e In DataRows Select e Where _

e.Stand = Stand.Value

DataRows = ObjectValB.ToArray

End If

If Not String.Equals(CmbxErr.SelectedValue, "Alle") Then

Dim ObjectValsC = From e In DataRows Select e Where _

e.ErrMsgs.Contains(CmbxErr.SelectedValue.ToString)

'Dit kan dus ook

'' e.ErrMsgs Like String.Concat("*", CmbxErr.SelectedValue, "*")

DataRows = ObjectValsC.ToArray

End If

Me.txtbxFilter.Text = DataRows.Count.ToString



Me.GetRadioMeterErrorsBindingSource.DataSource = DataRows

End Sub

</SNIP>

Me.DsRadioMeters is the dataset wich is filled on program startup , with
the definition of this dataset i have setup all my databound controls ( in
this case 2 datagrids and 1 combobox )
as the GetRadioMeterErrors might contain hundreds of rows ( mostly 700 +
_ ) i have made several filters that may be used in LINQ the application
is lightning fast

so i just rebind the datarows ( datarow array ) to the BindingSource if
the user removes the filter i just rebind the original dataset this works
great for me and i can use the designer to setup my datagridview .

HTH

And regards

Michel Posseth [MCP]
http://www.linkedin.com/in/michelposseth



Ivan said:
Hi,

I've got a problem with a query I make using Linq. The problem is that I
want to show the results in a DataGridView. Until now I had used it
without problems using CopytoDataTable(), but this time this method is
not appliable, it doesn't exist as a method for this query...

This is the code from the query
*******************************************
Dim Source= ds.Tables(0).AsEnumerable()
Dim Change = ds.Tables(1).AsEnumerable()

Dim query = _
From f In Source _
Group Join c In Change On _
f.Field(Of String)("Name") Equals c.Field(Of String)("Name") _
Into children = Group _
From child In children.DefaultIfEmpty() _
Select New With _
{ _
.Order = f.Field(Of Integer)("Order"), _
.Name = f.Field(Of String)("Name"), _
.FPosition = f.Field(Of String)("Position"), _
.cPosition = child.Field(Of String)("Position") _
}

DataGridView1.DataSource = query.CopytoDataTable()??**

************************************************
**Here is where it fails. Until now, with easier queries, i could apply
this method, but this time it seems as it's not implemented...

CAN ANYBODY HELP MEEEEEEE!!??

Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top