Hello if i execute the following query in PhpMyAdmin i have 5 Result.
If i execute the exactly query into C# i get back only 1 Result.
I have been beating my head against the table for 2 days but I can’t find the solution.
Some ideas?
SELECT
tbl_orders.Data_payment,
tbl_customers.City,
tbl_customers.Country,
tbl_orders.Price,
tbl_orders.state_order,
tbl_products.Product_ID,
tbl_products.Name
FROM
tbl_orders
INNER JOIN
tbl_customers ON tbl_orders.fk_customer_id = tbl_customers.Customer_ID
INNER JOIN
tbl_products ON tbl_orders.fk_product_id = tbl_products.Product_ID
WHERE
tbl_products.Product_ID = '2'
AND tbl_customers.Country = 'Russia'
AND tbl_orders.Data_payment BETWEEN '2019-04-01' AND '2020-04-01'
private void test_load(string query)
{ DataTable dt = new DataTable();
try
{
using (MySqlConnection conn = new MySqlConnection(MyConString))
{
using (MySqlCommand cmd = new MySqlCommand(query, conn))
{
conn.Open();
using (MySqlDataReader dr = cmd.ExecuteReader())
{
dt.Load(dr);
MessageBox.Show(dt.Rows.Count.ToString());
dataGridView1.DataSource = dt;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("err test_load " + ex);
}
}
2
Answers
Ok so i finally solve the problem.
This pice of code in not working it return only one row and should return more than one.
This is working. It return the right number of rows
After adding the database and testing the code you provided, I find that I still
can not reproduce your problem. I can get the same result in sql-query and in c# code.
You can see the following picture.
I also tested it, I find it is different from your picture.