Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

datatable.select with filter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jmhmaine - 28 Jul 2005 15:37 GMT
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.
Bart Mermuys - 28 Jul 2005 19:43 GMT
Hi,

>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))
[quoted text clipped - 54 lines]
>
> Josh.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.