Click here to Skip to main content
16,017,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Heloo,

I have created 4 arays, 2 for a first select from database:

C#
Program.Connection.CommandText = "SELECT ......................";
                    Program.Connection.AddParameter("@dataInceput", PrimaZiDinLuna);
                    Program.Connection.AddParameter("@dataSfarsit", UltimaDataDinLuna);
                    
                    DataTable TableNirProduse = new DataTable();
                    Program.Connection.FillDataTable(TableNirProduse, true);

                    decimal[] SoldIntrari = new decimal[TableNirProduse.Rows.Count];
                    int[] CatProdusNr = new int[TableNirProduse.Rows.Count];

                    for (int j = 0; j < TableNirProduse.Rows.Count; ++j)
                    {
                        SoldIntrari[j] = Convert.ToDecimal(TableNirProduse.Rows[j]["PretPropusVanzare"].ToString());
                        CatProdusNr[j] = Convert.ToInt32(TableNirProduse.Rows[j]["CatProdus"].ToString());
                    }


and another 2 array for a selet select:

C#
Program.Connection.CommandText = "SELECT ................";
                    Program.Connection.AddParameter("@dataInceput", PrimaZiDinLuna);
                    Program.Connection.AddParameter("@dataSfarsit", UltimaDataDinLuna);

                    DataTable TableNirProduseVandute = new DataTable();
                    Program.Connection.FillDataTable(TableNirProduseVandute, true);

                    decimal[] SoldProduseVandute = new decimal[TableNirProduseVandute.Rows.Count];
                    int[] CatProdusNrVandut = new int[TableNirProduseVandute.Rows.Count];

                    for (int i = 0; i < TableNirProduseVandute.Rows.Count; ++i)
                    {
                        SoldProduseVandute[i] = Convert.ToDecimal(TableNirProduseVandute.Rows[i]["PretVanzare"].ToString());
                        CatProdusNrVandut[i] = Convert.ToInt32(TableNirProduseVandute.Rows[i]["CatProdus"].ToString());

                        
                    }

Both query select group record by CatProdusNr, and CatProdusNrVandut and make SUM(), for each group.

I need to save in my database the sum for each category from the first query, and ADD (+) the sum from second query to the category they correspond.


Now a what to save the result from twos 2 select back to database, i don't now how to check the equality from those arrays:

For example:

if CatProdusNr[j] == CatProdusNrVandut[i] - save to database.

Atother problem is that the first select has a number of record, and second select is possible to be different in number of records.

For example:

I have in my database (first query select) - 4 record (CatProdusNr[4] = {5,6,10,11} )

and in second query - 1 record (CatProdusNrVandut[1] = {5})

or vice-versa.

How doo i save in database those values.
Posted
Comments
ZurdoDev 6-Feb-14 7:51am    
I'm confused but it sounds like you really need to do all of this in SQL and not try to compare values in C#.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900