I have a problem in displaying the data in crystal report using left join. When i use "where no_barang = 2" in Phpmyadmin is working. But in crystalreport not working (the data is duplicate, and showing all data).
table "barang"
no_barang | nama_barang | harga_barang
1 | sepatu | 25000
2 | baju | 47000
table "pelanggan"
no_pelanggan | nama_pelanggan
1 | Sugeng Agung Suganda
2 | Babay Azifahmi
table "pembelian"
no_order | no_pelanggan | no_barang | jumlah
1 | 1 | 2 | 2
2 | 2 | 1 | 1
This my code in crystalreport
- MySqlParameter p;
- MySqlConnection conn = new MySqlConnection("database=cs_reportmultitables;server=localhost;uid=root;pwd=");
-
- public View(string sTitle)
- {
- InitializeComponent();
- try
- {
- DataSet ds = new DataSet();
- string query;
- p = new MySqlParameter("@no_order", MySqlDbType.String);
- p.Value = sTitle;
- query = "SELECT pembelian.no_order, pelanggan.nama_pelanggan, barang.nama_barang, barang.harga_barang, pembelian.jumlah FROM pembelian LEFT JOIN pelanggan ON pembelian.no_pelanggan = pelanggan.no_pelanggan LEFT JOIN barang ON pembelian.no_barang = barang.no_barang WHERE no_order=@no_order";
- MySqlDataAdapter dscmd = new MySqlDataAdapter(query, conn);
- dscmd.SelectCommand.Parameters.Add(p);
- dscmd.Fill(ds);
- RPT cryds = new RPT();
- cryds.SetDataSource(ds.Tables[0]);
- crystalReportViewer1.ReportSource = cryds;
- crystalReportViewer1.Refresh();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- conn.Close();
- }
- conn.Close();
- }
I have trying to all combination settings in crystal report.
Trying to display number 2 and my output was this:
no_order | nama_pelanggan | nama_barang | harga_barang | jumlah
1 | Sugeng Agung Suganda | sepatu | 25000 | 2
2 | Babay Azifahmi | sepatu | 25000 | 1
It duplicate in "nama_barang" and "harga_barang", should display data like this:
2 | Babay Azifahmi | sepatu | 25000 | 1
Please help me if anyone know? Full my source code is here
http://github.com/sgnd/csharp-reportmultitables