0

In my wpf application im trying to fill my pivot table with data: Tables: Product -id -name -barcode -price

Order -id -total_price

Product_order -id -order_id -product_id

I am pulling data from a Listbox, inside this listbox i made a grid with multiple stackpanels. But now i want to add all the ID's from the stackpanels. but i keep getting errors like: use of unassigned local variable productId on this line of code

productId[P] = textBlock.Text;

can someone explain why this is happening. ive been looking around on the internet but cant find a good explanation

foreach (var item in LbPrices.Items)
                {
                    Grid container = item as Grid;

                    if (container != null)
                    {
                        foreach (var child in container.Children)
                        {
                            StackPanel stackPanel = child as StackPanel;

                            if (stackPanel != null)
                            {
                                string[] productId;    
                                string allPrice = string.Empty;
                                string AmountBought = string.Empty;

                                foreach (var grandChild in stackPanel.Children)
                                {
                                    TextBlock textBlock = grandChild as TextBlock;

                                    if (textBlock != null)
                                    {
                                        if (textBlock.Name == "product_id")
                                        {
                                            productId[P] = textBlock.Text;
                                        }
                                        
                                        if (textBlock.Name.StartsWith("AmountBack"))
                                        {
                                            AmountBought = textBlock.Text;
                                        }
                                        // Retrieve the price from the TextBlock with the name "AllPrice"
                                        if (textBlock.Name.StartsWith("AllPrice"))
                                        {
                                            allPrice = textBlock.Text;

                                        }
                                        //retrieve the barcode from the TextBlock with the name "BarcodeUsed"
                                     

                                    }
                                    P++;
                                }
                                if (!_db.Create_order(productId[], AmountBought, allPrice, total, Employee_number))
                                {

                                }
                            }
                        }
                    }
                }

ive been looking on the internet and found no usefull information about why this happens

D1llie
  • 1
  • 1

0 Answers0