problem when i try printing sales invoice

◇◆丶佛笑我妖孽 提交于 2020-01-22 02:32:18

问题


private void button1_Click(object sender, EventArgs e)
{
    hesham2020Entities2 db = new hesham2020Entities2();
    string u;
    u = textBox1.Text.Trim();
    var y = from v in db.inv_detail
            from s in db.invoice_head 
            where s.invno==u
            select new
                {v.unit,v.qty,v.p_no,v.description,v.price,v.tot_price,s.invno,s.customer_id,s.inv_dat,s.po_no,s.total,s.currency};
    CrystalReport6 crt = new CrystalReport6();
    crt.SetDataSource(y);
    crv9.Refresh();
    crt.SetParameterValue(0, comboBox2.SelectedItem);
    crt.SetParameterValue(1, comboBox3.SelectedItem);
    //crt.SetParameterValue(2, textBox1.Text);
    crv9.ReportSource = crt;
    crv9.Refresh();
}

when i try to print this invoice if the invoice details contain 3 rows it printed 9 rows, that mean every row printed 3 times, but when the invoice details contain 1 row it printed 1 row. i can not know the reason of the error


回答1:


You are missing the join between inv_detail and invoice_head. Basically you are doing a cartesian product, you should try something like:

from db.invoice_head 
join db.inv_detail
on [...]



回答2:


I think the following code can help you, maybe you forgot to use join correctly.

I used Id property for Join

var y = (from v in db.inv_detail
                 join  s in db.invoice_head on v.HeaderId equals s.Id
            where s.Id == u
                 select new
            {
                v.Id
            }).ToList();

or

var query = db.inv_detail
            .Join(db.invoice_head, 
                post => post.HeaderId,       
                meta => meta.Id,  
                (post, meta) => new { Post = post, Meta = meta }) 
            .Where(postAndMeta => postAndMeta.Post.Id == u);  


来源:https://stackoverflow.com/questions/59456133/problem-when-i-try-printing-sales-invoice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!