问题
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