内部联接获得重复价值-需要紧急帮助 [英] Inner Join getting repeated value--Urgent Help needed

查看:56
本文介绍了内部联接获得重复价值-需要紧急帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要紧急帮助
对于我的select语句,我正在使用三个表
1.客户详细信息
2. InvoiceItem
3. InvoiceParent
我得到了重复的值
一条记录显示4次.
请纠正我.

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;
        }


    }


感谢

推荐答案

将您的select语句带到SQL Server Management Studio(免费下载)并在其中运行.

更改选择字段....以选择*进行测试.

现在注释掉联接,直到获得预期的结果.

可以确定问题所在,现在分析问题.
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.


您可以使用此链接.希望对您有帮助


http://databases.about.com/od/sql/a/multiple_joins.htm
you can use this link..Hope its helpful to you


http://databases.about.com/od/sql/a/multiple_joins.htm


这篇关于内部联接获得重复价值-需要紧急帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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