dpdmembers
asked on
In-Memory Query
I have the following code:
Dim xAll = (From xx In _Context.Vessel_Owners
Select xx)
Dim xSearch1 = (From xx In _Context.Vessel_Owners
Where xx.Natregno = txtNatregnoSearch.Text.ToS tring()
Select xx)
Dim xSearch2 = (From xx In _Context.Vessel_Owners
Where xx.Passport_No = txtPassportNoSearch.Text.T oString()
Select xx)
Dim xSearch3 = (From xx In _Context.Vessel_Owners
Where xx.Owner_Surname = txtOwnerSurnameSearch.Text .ToString( )
Select xx)
Dim xSearch4 = (From xx In _Context.Vessel_Owners
Where xx.Owner_Firstname = txtOwnerFirstnameSearch.Te xt.ToStrin g()
Select xx)
Dim finalQuery = CreateEmptyEnumerable(xAll )
If Not String.IsNullOrEmpty(txtNa tregnoSear ch.Text.To String()) Then
finalQuery = xSearch1
End If
If Not String.IsNullOrEmpty(txtPa ssportNoSe arch.Text. ToString() ) Then
finalQuery = finalQuery.Union(xSearch2)
End If
If Not String.IsNullOrEmpty(txtOw nerSurname Search.Tex t.ToString ()) Then
finalQuery = finalQuery.Union(xSearch3)
End If
If Not String.IsNullOrEmpty(txtOw nerFirstna meSearch.T ext.ToStri ng()) Then
finalQuery = finalQuery.Union(xSearch4)
End If
The finalQuery is producing an In-Memory Query which I am trying to transform into a Datatable.
When I do the following: Dim dr = TryCast(finalQuery , DataTable)
dr is returning Nothing
How can i get the finalQuery into a Datatable?
Dim xAll = (From xx In _Context.Vessel_Owners
Select xx)
Dim xSearch1 = (From xx In _Context.Vessel_Owners
Where xx.Natregno = txtNatregnoSearch.Text.ToS
Select xx)
Dim xSearch2 = (From xx In _Context.Vessel_Owners
Where xx.Passport_No = txtPassportNoSearch.Text.T
Select xx)
Dim xSearch3 = (From xx In _Context.Vessel_Owners
Where xx.Owner_Surname = txtOwnerSurnameSearch.Text
Select xx)
Dim xSearch4 = (From xx In _Context.Vessel_Owners
Where xx.Owner_Firstname = txtOwnerFirstnameSearch.Te
Select xx)
Dim finalQuery = CreateEmptyEnumerable(xAll
If Not String.IsNullOrEmpty(txtNa
finalQuery = xSearch1
End If
If Not String.IsNullOrEmpty(txtPa
finalQuery = finalQuery.Union(xSearch2)
End If
If Not String.IsNullOrEmpty(txtOw
finalQuery = finalQuery.Union(xSearch3)
End If
If Not String.IsNullOrEmpty(txtOw
finalQuery = finalQuery.Union(xSearch4)
End If
The finalQuery is producing an In-Memory Query which I am trying to transform into a Datatable.
When I do the following: Dim dr = TryCast(finalQuery , DataTable)
dr is returning Nothing
How can i get the finalQuery into a Datatable?
ASKER
In the Immediate window I get the following:
?finalQuery
In-Memory Query
Results: Expanding will process the collection
When you expand the process you see all the records.
?finalQuery
In-Memory Query
Results: Expanding will process the collection
When you expand the process you see all the records.
ASKER
I have a attached a copy of what u see when u moused over the finalQuery
finalQuery.png
finalQuery.png
Hi dpdmembers
The problem you are having is that the type Vessel_Owners can not be converted / cast to a datatable. The reason it is not throwing an error is that the TryCast does not throw an exception if an error happens it will return Nothing when an exception has happened.
In order to convert it to a DataTable you will need to iterate over the result set and get a new row from the DataTable by using DataTableInstance.NewRow() and then filling in the column data. But before starting you will need to create a DataTable with all of its columns defined.
The problem you are having is that the type Vessel_Owners can not be converted / cast to a datatable. The reason it is not throwing an error is that the TryCast does not throw an exception if an error happens it will return Nothing when an exception has happened.
In order to convert it to a DataTable you will need to iterate over the result set and get a new row from the DataTable by using DataTableInstance.NewRow()
ASKER
Can u please send me a link with that example in VB preferably. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Would be nice to see if that finalQuery is syntactically correct.
Alan