Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to bind crystal report from multiple datatables using one dataset in asp.net c#?
Posted

Dear , you need to create a Add Command for that and in that you specify Union Query for that.
this done in using the ADD COMMAND...

and another thing is that "You need to Create Join Query for Return the Value from Different Table"

for Example..this example shows different from different database...

select * from db1.dbo.cust_list where Condtion
union all
select * from db2.dbo.cust_list where condition
union all
select * from db3.dbo.cust_list where condition


make sure your Query Returns same number of Columns from all database..



if any query, please post it....
 
Share this answer
 
v3
Comments
[no name] 23-Aug-12 3:58am    
+5
[no name] 23-Aug-12 4:16am    
thanks Sourav..
veenusethi 23-Aug-12 4:56am    
I want to use two datatables like this

string query = " select saleitemadd.*,companymaster.address etc... wherecompanyname='"+HiddenField1.Value +"'";
con = new SqlConnection(strConn);
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds,"saleitemadd");
rptDoc.Load(Server.MapPath("salereport.rpt"));
rptDoc.SetDataSource(ds.Tables["saleitemadd"]);// but here problem is occur ?

i don't know how take two or more than two datatable from one?
companymaster and saleitemad tables have a pk-fk relation.
please help me how to show crystal report using more than datarables?

saleitemadd and companymaster are tableadapters
veenusethi 23-Aug-12 4:57am    
and by the way thanks for ur reply
[no name] 23-Aug-12 5:01am    
you must use the Join Query in that and use Common field which is in both the table in Where Claue
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:-

SQL
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
 
Share this answer
 
Comments
AmitPandey1988 6-Nov-12 0:53am    
HI veenu,
i am making one project in which i am developing store module,in which user have to prepare challan in which have to select the client name and address from database and generating unique id, this info is saved in a different table, in the same page i am selecting the products also and making a table which has the unique id as a name of table.after all this i am making one invoice(bill) in which i am taking all data from these tables. now the problem is i have to make the invoice page printable and have to make the report. Would anyone please help me??????????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900