I have this piece of code:
string getOrder = "SELECT * FROM `wpet_woocommerce_order_items` a LEFT JOIN `wpet_woocommerce_order_itemmeta` b ON a.order_item_id = b.order_item_id LEFT JOIN `wpet_users` f ON f.ID = b.meta_value AND b.meta_key = 'seller_id' LEFT JOIN `wpet_dokan_orders` c ON a.order_id = c.order_id LEFT JOIN `wpet_posts` d ON a.order_id = d.ID WHERE a.order_id =" + cx.Field<ulong>("ID") + " AND a.order_item_type = 'line_item' AND d.post_status = 'wc-completed';";
conn.Open();
MySqlCommand cmd = new MySqlCommand(getOrder, conn);
status.Text = conn.State.ToString();
MySqlDataAdapter dt = new MySqlDataAdapter(cmd);
DataTable wcOrder_data = new DataTable();
dt.Fill(wcOrder_data);
GridView3.DataSource = wcOrder_data;
GridView3.DataBind();
var toListing = wcOrder_data.Select().ToList();
conn.Close();
var getUniqueItems = wcOrder_data.AsEnumerable().Where(x => x.Field<ulong>("order_item_id") > 0).GroupBy(x => x.Field<ulong>("order_item_id")).Select(g => new
{
ItemID = g.Key.ToString(),
ItemName = g.Select(x => x.Field<string>("order_item_name")).FirstOrDefault(),
Order = g.Select(x => x.Field<UInt64>("order_id").ToString()).FirstOrDefault(),
Vendor = g.Select(x => x.Field<Int64>("seller_id")).FirstOrDefault().ToString(),
ItemAmount = g.Where(x => x.Field<string>("meta_key") == "_line_subtotal").Select(x => x.Field<string>("meta_value").ToString()).FirstOrDefault(),
ItemLineTotal = g.Where(x => x.Field<string>("meta_key") == "_line_total").Select(x => x.Field<string>("meta_value").ToString()).FirstOrDefault(),
Commission = g.Where(x => x.Field<string>("meta_key") == "_dokan_commission_rate").Select(x => x.Field<string>("meta_value").ToString()).FirstOrDefault(),
Qty = g.Where(x => x.Field<string>("meta_key") == "_qty").Select(x => x.Field<string>("meta_value").ToString()).FirstOrDefault(),
CommissionToMall = double.Parse(g.Where(x => x.Field<string>("meta_key") == "_line_subtotal").Select(x => x.Field<string>("meta_value")).FirstOrDefault()) * (double.Parse(g.Where(x => x.Field<string>("meta_key") == "_dokan_commission_rate").Select(x => x.Field<string>("meta_value")).FirstOrDefault()) / 100),
OrderDate = g.Select(x => x.Field<DateTime>("post_date")).FirstOrDefault(),
SellerEmail = g.Select(x => x.Field<string>("user_email")).FirstOrDefault(),
VendorName = g.Select(x => x.Field<string>("display_name")).FirstOrDefault(),
});
Which returns a null reference error, I am truly stumped by this because the gridview in this code returns data, I do not know why I have this error:
ERROR: Value cannot be null. Parameter name: value::::::mscorlib::: at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Double.Parse(String s) at App.tester.<>c.b__2_2(IGrouping`2 g) in C:\Users\Kent\Documents\Visual Studio 2015\Projects\App\tester.aspx.cs:line 60 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at App.tester.Button1_Click(Object sender, EventArgs e) in C:\Users\Kent\Documents\Visual Studio 2015\Projects\App\tester.aspx.cs:line 84
What I have tried:
I have tried all sorts of fixes, getting the data into a list, but it keeps returning null reference. The error also I do not fully understand. Please let someone assist me with this. Thanks.