如何将数据从datagridview传递到crystal report然后打印 [英] How to pass data from datagridview to crystal report and then print
问题描述
您好b $ b
我有一个下拉列表,其中有5个选项耳环,项链,手镯,戒指,手镯
旁边我有两个按钮。 1显示按钮和1个打印按钮。
点击下拉列表中的任何选项,然后点击show,显示该特定类型的gridview数据。 br />
例如
sl.no类别成本价格售价
2耳环200 400
3耳环5000 3000
7耳环7000 2000
现在我想点击打印按钮,这些数据将在水晶报告中显示并直接从那里打印。
怎么办?
i也创建了数据集。
i也会附上代码。
Hi
I have a drop down list which has 5 options earrings, necklace,bangles,rings, bracelets
and beside that i have two buttons. 1 show button and 1 print button.
on clicking any of the options from drop down list, then clicking on show,the gridview data shows of that particular type.
e.g
sl.no category cost price sold price
2 earrings 200 400
3 earrings 5000 3000
7 earrings 7000 2000
now i want clicking on print button, these data to be showed in crystal report and print directly from there.
how to do so?
i have created dataset also.
i will attach the code also.
private DataSet GetAllJewellery()
{
using (SqlConnection con = new SqlConnection(JewelleryHelper.GetConnectionString()))
{
using (SqlCommand cmd = new SqlCommand("spGetJeweleryOnSoldItems", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Category", SqlDbType.VarChar).Value = ddlCategory.SelectedItem.Text;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
con.Close();
return ds;
}
}
}
protected void btnPrint_Click(object sender, EventArgs e)
{
SoldItemsDataSetTableAdapters.spGetJeweleryOnSoldItemsTableAdapter getAllJewellerySoldItems = new SoldItemsDataSetTableAdapters.spGetJeweleryOnSoldItemsTableAdapter();
DataTable dt = getAllJewellerySoldItems.GetAllJewellerySoldItems(this.ddlCategory.SelectedValue);
ReportDocument rDoc = new ReportDocument();
rDoc.Load(Server.MapPath("soldCrystalReport.rpt"));
rDoc.SetDataSource(dt);
rDoc.SetParameterValue("Category", this.ddlCategory.SelectedValue);
this.crystalReportViewer.ReportSource = rDoc;
this.crystalReportViewer.DataBind();
this.crystalReportViewer.Focus();
}
}
但它还没来。
任何人都可以帮助我。
谢谢
因为我在这里停留了4天。
but its not coming.
can anyone please help me.
Thanks
as i am stuck in here for the last 4 days.
推荐答案
这是我要告诉你的简单方法,你可以根据自己的需要制作它。
1 - 在DataGridView中创建具有相同列的水晶报表。
2 - 根据您的要求创建数据表,然后分配用于DataGridView的数据表并用作Crystal Report的数据源。
这是一篇详细的完整文章,如果你是初学者,你可以从中获得帮助。
Data CridView到C#中的Crystal Report [ ^ ]
干杯,享受编码:)
This is simple method I am going to tell you, you can make it according to your need.
1-Make a crystal report with same columns present in the DataGridView.
2-Make your Datatable according to your requirements and then assign that datatable used for DataGridView and used as Datasource for Crystal Report.
Here is a detailed complete article you can take help from it if you are beginner.
DataGridView to Crystal Report in C#[^]
Cheers,Enjoy Coding :)
这篇关于如何将数据从datagridview传递到crystal report然后打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!