Getting a can not be NUll in my code C# and Linq query

59 views Asked by At

I am getting a can not be null in my code and im not for sure why how do I add in default XXXXX for place that have empty data. I just want to try to get this to load in my table. This code takes 3 tables and excel sheet sql table and oracle table I load all 3 in there own table in code behind for right now.

 var etjoin = from e in ExcelData.AsEnumerable()
                join t in TstarData.AsEnumerable() on e.Field<String>("IP Address") equals t.Field<String>("UserDefinedColumn3")
                into leftjointable 
                from x in leftjointable.DefaultIfEmpty()
                select new
                {
                    TS_IP = x.Field<String>("UserDefinedColumn3") != null ? x.Field<String>("UserDefinedColumn3") : "xxxxxx",
                    TS_VehicleName = x.Field<String>("VehicleName") != null ? x.Field<String>("VehicleName") : "xxxxxx",
                    TS_VehicleGroupName = x.Field<String>("VehicleGroupName") != null ? x.Field<String>("VehicleGroupName") : "xxxxxx",
                    TS_Phone = x.Field<String>("UserDefinedColumn2") != null ? x.Field<String>("UserDefinedColumn2") : "xxxxxx",
                    EX_IP = e.Field<String>("IP Address") != null ? e.Field<String>("IP Address") : "xxxxxx",
                    EX_ICCID = e.Field<String>("ICCID") != null ? e.Field<String>("ICCID") : "xxxxxx",
                    EX_Status = e.Field<String>("SIM Status") != null ? e.Field<String>("SIM Status") : "xxxxxx",
                    Ex_Session = e.Field<String>("In Session") != null ? e.Field<String>("In Session") : "xxxxxx",
                    Ex_Activated = e.Field<String>("Activated") != null ? e.Field<String>("Activated") : "xxxxxx"

                };
        // use ? operator on all columns to return empty string or something



        var fulljoin = from e in etjoin
                       join m in M5Data.AsEnumerable() on e.TS_VehicleName equals m.Field<String>("Unit_No")
                       into leftjointable
                       from x in leftjointable.DefaultIfEmpty()
                       select new
                       {
                           TS_IP = e.TS_IP,
                           TS_VehicleName = e.TS_VehicleName,
                           TS_VehicleGroupName = e.TS_VehicleGroupName,
                           TS_Phone = e.TS_Phone,
                           EX_IP = e.EX_IP,
                           EX_ICCID = e.EX_ICCID,
                           EX_Status = e.EX_Status,
                           EX_Session = e.Ex_Session,
                           Ex_Session = e.EX_Status,
                           M5_Unit_No = x.Field<String>("Unit_No"),
                           M5_Unit_ID = x.Field<String>("Unit_ID"),
                           M5_Using_Dept = x.Field<String>("Using_Dept"),
                           M5_Status = x.Field<String>("Status"),
                           M5_Using_Dept_Desc = x.Field<String>("Using_Dept_Desc"),
                           M5_Most_Recent_Chane = x.Field<String>("Most_Recent_Change_DT")
                           //Unit_ID, Using_Dept, Status, Using_Dept_Desc,
                       };

        foreach (var row in fulljoin)
        {
            Table.Rows.Add(row);
        }
0

There are 0 answers