Crystal reports create so much problems for me. one of them was how to bnd crystal report from multiple datatables using one dataset?
but now i solved this problem myself
1) firstly i was using joins in query but in datasource i was unable to give table name
then i create view in which i use join query
join query is:-
SELECT companymaster.address, companymaster.tin, saleitemadd.vch, saleitemadd.item, saleitemadd.qty, saleitemadd.rate,
saleitemadd.amount, saleitemadd.tax, saleitemadd.totaltax, saleitemadd.totalamount, saleitemadd.companyname, saleitemadd.party,
saleitemadd.date1, saleitemadd.discount
FROM companymaster INNER JOIN
saleitemadd ON companymaster.companyname = saleitemadd.companyname AND
companymaster.companyname = saleitemadd.companyname
and then i execute query and save view and then in dataset i add tableadapter and then choose view tab and then select my view table.
And after that i create crystal report and i call dataset and select view table
and in c# i use these lines of code
public partial class saleitemvoucherbill : System.Web.UI.Page
{
string strConn;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet("salereport");
private ReportDocument rptDoc = null;
protected void Page_Load(object sender, EventArgs e)
{
strConn = ConfigurationManager.ConnectionStrings["ConnectionASPX"].ConnectionString;
con = new SqlConnection(strConn);
con.Open();
if (Session["cmpny"] != null)
hdcompany.Value = Session["cmpny"].ToString();
this.rptDoc = new ReportDocument();
if (Session["vchbill"] != null)
hdbill.Value = Session["vchbill"].ToString();
if (Session["date"] != null)
date.Value = Session["date"].ToString();
if (Session["party"] != null)
hdparty.Value = Session["party"].ToString();
string query = " select * from salebillreport where vch='"+hdbill.Value +"' and companyname='"+hdcompany.Value +"'" ;
// in query salebillreport is view name and hdbill.value and hdcompany.value are hiddenfields and here values are coming through sessions
con = new SqlConnection(strConn);
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds,"salebillreport");
rptDoc.Load(Server.MapPath("saleitembillreport.rpt"));
rptDoc.SetDataSource(ds);
//parameter pass
DateTime fromdate = Convert.ToDateTime(date.Value);
rptDoc.SetParameterValue("date", fromdate);
rptDoc.SetParameterValue("party", hdparty.Value);
rptDoc.SetParameterValue("company", hdcompany.Value);
rptDoc.SetParameterValue("bill", hdbill.Value);
//// this code is used for clear the report after selection means refreshing the report
CrystalReportViewer1.ParameterFieldInfo.Clear();
CrystalReportViewer1.ReportSource = rptDoc;
}
Thank you if You like this please vote for me
Happy coding