linq query giving message "Value cannot be null"

Dear Experts,

The code below has come a long way and i am already proud of it. However i am getting a message    "Value cannot be null" of the line that starts with Dim query = From.... I really dont know how to about this .

Thank you

Dim tbl_time As DataTable = ds.Tables("ctime")
        Dim tbl_perhour As DataTable = ds.Tables("perhour")
        Dim tbl_area As DataTable = ds.Tables("areas")
        Dim tbl_basestation As DataTable = ds.Tables("station")
        Dim tbl_country As DataTable = ds.Tables("country")
        Dim tbl_ded As DataTable = ds.Tables("ded")

        Application.DoEvents()

                Dim query = From obj_perhour In tbl_perhour.AsEnumerable() Join obj_time In tbl_time.AsEnumerable() _
                    On obj_perhour.Field(Of Int64)("time_key") Equals obj_time.Field(Of Int64)("time_key") _
                    Group obj_perhour By customerid = obj_perhour.Field(Of Int64)("msisdn_nsk") _
                                     Into grp = Group _
                       Select New With _
                            { _
                              .msisdn = customerid,
                              .rev_onn_tot_nbn = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("ccost"), 0))
                             }
LVL 1
Anthony MatovuBusiness Analyst, MTN UgandaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
I have searched for help and made option changes from page

And now the error is at line

  public static EnumerableRowCollection<DataRow> AsEnumerable(this DataTable source)
        {
            DataSetUtil.CheckArgumentNull(source, "source");
           return new EnumerableRowCollection<DataRow>(source);
        }

datatableextensions.cs
Fernando SotoRetiredCommented:
Going back to the original post before the changes you made that change the location of the error. Try running the application and place a breakpoint on the statement after the query and post the actual exception and inner exception that is thrown. That type of message is normally sent when a collection / object is being processed and it is expecting a value but there is none.
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Hi, Below is the detailed massage i get

Thank you

System.ArgumentNullException was unhandled
  HResult=-2147467261
  Message=Value cannot be null.
Parameter name: source
  ParamName=source
  Source=System.Data.DataSetExtensions
  StackTrace:
       at System.Data.DataTableExtensions.AsEnumerable(DataTable source)
       at MTN_business_intelligence_solutions.mainfrm.Button1_Click(Object sender, EventArgs e) in C:\bi\MTN business intelligence solutions\mainfrm.vb:line 53
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MTN_business_intelligence_solutions.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Fernando SotoRetiredCommented:
What line in the code is it throwing the exception?
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Dim query = From obj_perhour In tbl_perhour.AsEnumerable() Join obj_time In tbl_time.AsEnumerable() _
                    On obj_perhour.Field(Of Int64)("time_key") Equals obj_time.Field(Of Int64)("time_key") _
                    Group obj_perhour By customerid = obj_perhour.Field(Of Int64)("msisdn_nsk") _
                                     Into grp = Group _
                       Select New With _
                            { _
                              .msisdn = customerid,
                              .rev_onn_tot_nbn = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("ccost"), 0))
                             }
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Dear Fernando,

Seems i am figuring out the cause of the problem.  utype was not properly spelt during table loading  and is likely to be the cause of the problem. it is now running and i waiting to see progress.
Fernando SotoRetiredCommented:
Hi MatovuAnthony;

That seems to be strange seeming all values would not of match and then returned a 0, zero, but should not have caused it to throw that type of exception.

I was thinking that one of the Int64 values was a null value and the reason I stated this in my first post, "That type of message is normally sent when a collection / object is being processed and it is expecting a value but there is none."
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Fortunately it run after i checked all spelling for my columns

Thank you for the help so far

Anthony
Fernando SotoRetiredCommented:
OK, that is different then your previous statement where you stated, "utype was not properly spelt ", which is a data type and was comparing it to a string.  This is the reason for my last statement and why I stated this, "I was thinking that one of the Int64 values was a null value ", which seems to have been the case because if the column name was misspelled the return value would have been a null and the reason why it threw the error.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi MatovuAnthony, did you understand my last post?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.