简体   繁体   中英

The number of records returned is different in the application than in the database

I am making corrections to an application that previously worked flawlessly and returned records perfectly. There was no problem. I have such a problem. It happens, for example, that I have 3 records with the status N and it returns 2. And so on. it just doesn't often return the same number of records to me as I have in the database. In the meantime, I often work on an application that works in production. And I noticed the dependence that, for example, an order such as 724xxx, which I do not see on my test application, is an order that I entered a moment earlier in production to see "what's inside" because unfortunately you have to work.

After entering the application, a given method is launched and it is responsible for connecting with orders.

public void Read_Main()
        {         
            
            try
            {
                using (OracleConnection conn = new OracleConnection(Connection.oradb))
                using (OracleCommand cmd = new OracleCommand("SELECT VBELN as ZLECENIE,KUNNR as ODBIORCA,DATA_ZLEC as DATA,UZEIT_ZLEC as GODZINA,MAIL_UTWORZYL as UTWORZYŁ,MAIL_PH as PH, STATUS as ST,WARTOSC_N AS WARTOSC FROM DWS1.AUTOMAT_NGL_POZ", conn))
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                        using (OracleDataReader reader = cmd.ExecuteReader())
                        {

                            reader.Read();

                            DataTable dataTable = new DataTable();
                            dataTable.Load(reader);



                            List<DataRow> newOrders = dataTable.AsEnumerable().Where(x => x.Field<string>("ST") == "N").ToList();


                            foreach (var item in newOrders)
                            {
                                Automation_Positive_Cena_2(conn, item["ZLECENIE"].ToString(), item["ODBIORCA"].ToString(), item["UTWORZYŁ"].ToString(), item["PH"].ToString());
                            }



                            dataGridView1.DataSource = dataTable;
                            dataGridView1.RowHeadersVisible = false;
                            dataGridView2.Hide();
                            label3.Show();
                            dataGridView2.DataSource = "";
                            negativetbox.Clear();



                        }
                        conn.Close();
                    }
                   
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Isn't that reader.read() discarding the first row of your data. Then you populate the DataTable ? Is that why you're getting one row less?

So try deleting that line and just filling the DataTable .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM