Avatar of Anthony Matovu
Anthony Matovu
Flag 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))
                             }
.NET ProgrammingVisual Basic.NETASP.NET

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Anthony Matovu

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
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.
Anthony Matovu

ASKER
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:
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Fernando Soto

What line in the code is it throwing the exception?
Anthony Matovu

ASKER
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 Matovu

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Fernando Soto

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 Matovu

ASKER
Fortunately it run after i checked all spelling for my columns

Thank you for the help so far

Anthony
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Fernando Soto

Hi MatovuAnthony, did you understand my last post?
Your help has saved me hundreds of hours of internet surfing.
fblack61