Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi
I need a urgent help
for my select statement i am using three table
1. CustomerDetails
2. InvoiceItem
3. InvoiceParent
I am getting repeated values
one record is displaying for 4 time.
Please correct me.

public void viewInvoiceByCompanyName(string cid, GridView viewingv)
    {
        try
        {
            DataSet ds = new DataSet();
            string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
            string selectSql = "Select CustomerDetails.CompName,InvoiceParent.InvDate,InvoiceParent.InvoiceNo,InvoiceParent.CusId,InvoiceParent.PoNo,InvoiceParent.DoNumber,InvoiceParent.PayTerms,InvoiceParent.DueDate,InvoiceParent.ShipDate,InvoiceItem.ItemNo, InvoiceItem.Description,InvoiceItem.Qty,InvoiceItem.UnitPrice,InvoiceItem.TotalAmount,InvoiceItem.SubTotal,InvoiceItem.Gst,InvoiceItem.Total,InvoiceItem.Deposit,InvoiceItem.AmountDue FROM CustomerDetails INNER JOIN InvoiceItem ON CustomerDetails.CusId = InvoiceItem.CusId INNER JOIN InvoiceParent ON CustomerDetails.CusId = InvoiceParent.CusId WHERE InvoiceParent.CusId = @cusId";
            SqlConnection conn = new SqlConnection(connectionString);
            SqlDataAdapter da = new SqlDataAdapter(selectSql, conn);
            da.SelectCommand.Parameters.AddWithValue("@cusId", cid);
            da.Fill(ds, "Items");
            viewingv.DataSource = ds.Tables["Items"];
            viewingv.DataBind();

        }
        catch (Exception ex)
        {
            string msg = ex.Message;
        }


    }

Thanks
Posted
Comments
Varun Sareen 13-Feb-12 1:55am    
Dear Friend,

There may be duplicate entries in one of your table. Please check that how the mapping is being done.

--Varun
Lancy.net 13-Feb-12 1:59am    
Thanks for your reply Friend
i checked dont have any duplicate entries......
is their any other possibilities....
Thanks

Take your select statement to SQL Server Management Studio (it's a free download) and run it there.

Change the select fields.... to Select * for testing.

Now comment out the joins till you get the expected results.

That identifies the problem, now analyse the issue.
 
Share this answer
 
Comments
Lancy.net 13-Feb-12 2:09am    
Thanks..
Tech Code Freak 13-Feb-12 3:27am    
5up!
you can use this link..Hope its helpful to you


http://databases.about.com/od/sql/a/multiple_joins.htm
 
Share this answer
 
v2

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



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