Link to home
Create AccountLog in
Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda

asked on

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))
                             }
Avatar of Anthony Matovu
Anthony Matovu
Flag of Uganda image

ASKER

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
Avatar of Fernando Soto
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.
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:
What line in the code is it throwing the exception?
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))
                             }
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.
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."
Fortunately it run after i checked all spelling for my columns

Thank you for the help so far

Anthony
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi MatovuAnthony, did you understand my last post?