Home > OS >  My database query is only querying the last element of my array
My database query is only querying the last element of my array

Time:12-29

My problem in the title i have allcodes array and codes TextBox (kodTxtBox) i will split textbox like line per element and querying all elements with for loop then when i run it, it shows the query of only the last element of the allcodes array with the messagebox, but the others go into else and giving error message box

some turkish words in my codes so.
aciklama = description
birim = monad
birimFiyat = Price per 1 unit
ürünler = products
ürünler.sipariskod = products.ordercode etc.

i did a lot of ways for this i used foreach all variables type is string

    allCodes = kodTxtBox.Text.Split('\n');
    for (int i = 0; i < allCodes.Length; i  )
    {
        queryString = "SELECT ürünler.siparisKod, ürünler.aciklama, ürünler.birim, ürünler.fGrup, ürünler.birimfiyat FROM ürünler WHERE (((ürünler.siparisKod)=\""   allCodes[i]   "\"));";
        using (OleDbCommand query = new OleDbCommand(queryString))
        {
            query.Connection = connection;
            reader = query.ExecuteReader();
            if (reader.Read())
            {
                MessageBox.Show(allCodes[i]   " Succesful");
                var desc = reader["aciklama"].ToString();
                var monad = reader["birim"].ToString();
                var sellPrice = reader["birimFiyat"].ToString();
                MessageBox.Show("Açıklama: "   desc   " Birim: "   monad   " Satış Fiyatı: "   sellPrice);
                reader.Close();
            }
            else
            {
                MessageBox.Show("Hata");
            }
        }
    }

CodePudding user response:

I solved the problem by making a single query instead of multiple queries. I saved the values ​​returned in each single query into a list and at the end I made the necessary for loop using the elements of the list

  • Related