Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In My Database 1 Row

In dataGridView Give My 3 rows not Real

This My Code
C#
 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
Posted
Updated 15-Jul-15 23:14pm
v3

1 solution

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.
 
Share this answer
 
Comments
Member 11280947 16-Jul-15 5:29am    
There is no duplicate rows in SQL
Wendelius 16-Jul-15 5:34am    
If you take the query fromyour code, replace the parameters with the values you have used and run it in the database using Sql Server Management Studio, do you get the correct amount of rows?
Member 11280947 16-Jul-15 5:43am    
NoIn Database 1 row
In dataGridView 4 rows
Wendelius 16-Jul-15 5:45am    
Then, using debugger, check how many rows the data table dt1 contains after the Fill.
Member 11280947 16-Jul-15 6:02am    
What Do You mean

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

  Print Answers RSS


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