PC Review


Reply
Thread Tools Rate Thread

datatable.select with filter

 
 
=?Utf-8?B?am1obWFpbmU=?=
Guest
Posts: n/a
 
      28th Jul 2005
I have the following code in a on page load event of a user control:

<Other Code>
Dim dt As DataTable ' Also tried using New
dt = m_ClaimHistoryEntity.DataTable 'Error occurs here
m_ClaimHistoryEntity.Clear()
m_ClaimHistoryEntity.Load(FilterTable(dt))

dgClaimHistory.DataSource = m_ClaimHistoryEntity.DataTable
<Other Code>

Private Function FilterTable(ByVal currDataTable As DataTable) As
DataTable
Dim filterExpress As New StringBuilder

If m_bOpenOnly = True Then
'Limit to Open Status
filterExpress.Append("(Status = 'Open' OR IsNull(Status,'') =
'')")
End If

Dim myRow As DataRow
Dim dt As DataTable
Dim rowSet As DataRow()

rowSet = currDataTable.Select(filterExpress.ToString)

For Each myRow In rowSet
dt.Rows.Add(myRow)
Next myRow

Return dt
End Function

I keep receiving the generic error:
Object reference not set to an instance of an object

My goal is simple, I have a populated datatable called:
m_ClaimHistoryEntity.DataTable

I want to a subset of the data in the table, so I want to apply a filter.
Based on the results I want to set a datagrid datasource called:
dgClaimHistory

The code above started with the following simple syntax that keep growing as
tried to isolate the error:

Dim filterExpress As New StringBuilder

If m_bOpenOnly = True Then
'Limit to Open Status
filterExpress.Append("(Status = 'Open' OR IsNull(Status,'') =
'')")
End If

dgClaimHistory.DataSource =
m_ClaimHistoryEntity.DataTable.Select(filterExpress.ToString)

It there is a better approach I'm open to suggestions. If possible, please
provide VB examples. Thanks.

Josh.
 
Reply With Quote
 
 
 
 
Bart Mermuys
Guest
Posts: n/a
 
      28th Jul 2005
Hi,

"jmhmaine" <(E-Mail Removed)> wrote in message
news:CD1BE135-8152-49B5-9706-(E-Mail Removed)...
>I have the following code in a on page load event of a user control:
>
> <Other Code>
> Dim dt As DataTable ' Also tried using New
> dt = m_ClaimHistoryEntity.DataTable 'Error occurs here


If you get an "Object reference not set to an instance of an object"
exception at the above line, then most likely m_ClaimHistoryEntity is not
initialized at that point, it is null. If ClaimHistoryEntity must be set by
a property then wait until it is set and do the binding then.

Once you have fixed that, you can filter using a DataView:

Dim dv as DataView
dv = m_ClaimHistoryEntity.DataTable.DefaultView

If ( m_bOpenOnly ) Then
dv.Filter = "Status = 'Open' OR IsNull(Status,'NULL') = 'NULL' "
End If

dgClaimHistory.DataSource = dv


HTH,
Greetings


> m_ClaimHistoryEntity.Clear()
> m_ClaimHistoryEntity.Load(FilterTable(dt))
>
> dgClaimHistory.DataSource = m_ClaimHistoryEntity.DataTable
> <Other Code>
>
> Private Function FilterTable(ByVal currDataTable As DataTable) As
> DataTable
> Dim filterExpress As New StringBuilder
>
> If m_bOpenOnly = True Then
> 'Limit to Open Status
> filterExpress.Append("(Status = 'Open' OR IsNull(Status,'') =
> '')")
> End If
>
> Dim myRow As DataRow
> Dim dt As DataTable
> Dim rowSet As DataRow()
>
> rowSet = currDataTable.Select(filterExpress.ToString)
>
> For Each myRow In rowSet
> dt.Rows.Add(myRow)
> Next myRow
>
> Return dt
> End Function
>
> I keep receiving the generic error:
> Object reference not set to an instance of an object
>
> My goal is simple, I have a populated datatable called:
> m_ClaimHistoryEntity.DataTable
>
> I want to a subset of the data in the table, so I want to apply a filter.
> Based on the results I want to set a datagrid datasource called:
> dgClaimHistory
>
> The code above started with the following simple syntax that keep growing
> as
> tried to isolate the error:
>
> Dim filterExpress As New StringBuilder
>
> If m_bOpenOnly = True Then
> 'Limit to Open Status
> filterExpress.Append("(Status = 'Open' OR IsNull(Status,'') =
> '')")
> End If
>
> dgClaimHistory.DataSource =
> m_ClaimHistoryEntity.DataTable.Select(filterExpress.ToString)
>
> It there is a better approach I'm open to suggestions. If possible, please
> provide VB examples. Thanks.
>
> Josh.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax for filter in datatable.select moondaddy Microsoft ADO .NET 4 16th Nov 2007 05:39 AM
filter in DataTable.Select =?Utf-8?B?Um95?= Microsoft Dot NET Framework 1 18th Oct 2006 08:49 PM
DataTable.Select(filter) Parameter too long? Filipe Correia Microsoft ADO .NET 11 26th May 2006 07:47 PM
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select Dan V. Microsoft C# .NET 3 1st Jul 2004 03:06 PM
DataTable.Select(string filter) Nico Microsoft ADO .NET 0 26th Aug 2003 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 PM.