Print Page | Close Window

problem from SQL expression with two tables

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6901
Printed Date: 18 May 2024 at 4:03am


Topic: problem from SQL expression with two tables
Posted By: limcpoo
Subject: problem from SQL expression with two tables
Date Posted: 29 Jun 2009 at 9:30pm
hi guy..I suffer now which is..

I got 1 database with the name as test and two table which is userdetails and userearns..

in the crystal report I oni drag and drop the field that I want..then in the c# program there I code as below..

string sql = null;

            string ConnectionString = @"driver={MySQL ODBC 5.1 Driver};server=localhost;database=test;uid=root;pwd=unified;";

            OdbcConnection myConnection = new OdbcConnection(ConnectionString);
            myConnection.Open();

            //sql = "select * from testtable where testcol1 like '" + txtSearch.Text + "%'";
            //sql = "select userid,isdate,amountearn,isname,sex from (select userid,isdate,amountearn from userearns) as A left join (select userid as userid_2,isname,sex from userdetails) as B on a.userid = b.userid_2";
            //sql = "select * from userearns e left outer join userdetails d on e.userid = d.userid";
            //sql = "select a.userid,a.isdate,a.amountearn,b.isname,b.sex from userearns a, userdetails b where a.userid = b.userid";
            sql = "select userid,isdate,amountearn from userearns";
            OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(sql, myConnection);

            DataSet ds = new DataSet();
            //dscmd.Fill(ds, "test");
            myDataAdapter.Fill(ds, "test");

            ReportDocument myReportDocument;
            myReportDocument = new ReportDocument();
            myReportDocument.Load("C:\\Users\\MIS User\\Documents\\Report File\\Test_report2.rpt"); // Here pass the crystall report file name
            
            myReportDocument.Database.Tables[0].SetDataSource(ds);
            //myReportDocument.SetDataSource(ds);
            //objRpt.SetDataSource(ds.Tables[1]);
            crystalReportViewer1.ReportSource = myReportDocument;
            crystalReportViewer1.Refresh();

It no error and problem and also can display it out..but the problem is it display repeadtly results..which is wrong output..may I know why this happen? it is urgent for me..ur help I will feel appreciate..thanks alotz



Print Page | Close Window