我的dataGridView给了我不依赖的数据 [英] My dataGridView give me not rel data

查看:68
本文介绍了我的dataGridView给了我不依赖的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中1行



在dataGridView中给我的3行不真实



这是我的代码

In My Database 1 Row

In dataGridView Give My 3 rows not Real

This My Code

 try
           {
               DataTable dt1 = new DataTable();
               //string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
               using (SqlConnection con2 = new SqlConnection("data source=Server;Database=MnStores; Integrated Security = False; User ID=; Password=; Trusted_Connection=false;"))
               {
                   string sqlstr1 =
"Select dr.ReceiptNote_id as 'Received Id', ct.Customer_name as 'Customer Name',dr.Receipt_Date as 'Received Date',dd.Product_Id as 'Product Id',dd.Product_name as 'Product Name' from Customers_TBL as ct
inner join   Receipt_NoteHeadTBL as dr on dr.Customer_id=ct.Customers_id
inner join  Receipt_NoteDetalisTBL as dd on dr.ReceiptNote_id=dd.Fk_ReceiptNote_id WHERE  ct.Customers_id = @Customers_id and dr.Receipt_Date >= @DT11 AND dr.Receipt_Date <= @DT22";

using (SqlDataAdapter dr1 = new SqlDataAdapter(sqlstr1, con2))
                   {
                       dr1.SelectCommand.Parameters.AddWithValue("@Customers_id", txtCustomersID2.Text);

                       dr1.SelectCommand.Parameters.AddWithValue("@DT11", @dateTimePicker1.Text);
                       dr1.SelectCommand.Parameters.AddWithValue("@DT22", @dateTimePicker2.Text);
                       dr1.Fill(dt1);
                       dataGridView1.DataSource = dt1;
                   }

               }
           }
           catch { }



某些发票重复且不真实


Some Invoice Duplicated And Not Real

推荐答案

如果SQL语句返回重复行,则很可能在连接条件中出错。也许是一个列失踪等。



因为你是唯一一个知道表之间的外键的人,你也是唯一可以检查它们的人。因此,再次浏览连接并重新检查是否正确提到所有连接列。
If the SQL statement return duplicate rows, you most likely have an error in the join conditions. Perhaps a column missing etc.

Since you're the only one who knows the foreign keys between the tables you're also the only one who can check them. So go through the joins again and re-check that all joining columns are mentioned correctly.


这篇关于我的dataGridView给了我不依赖的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆