Suganda Suganda

Suganda Suganda

  • 2k
  • 24
  • 6.4k

Duplicating data in crystal report with MySQL and C#

Mar 27 2018 1:53 PM

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

  1. MySqlParameter p;  
  2. MySqlConnection conn = new MySqlConnection("database=cs_reportmultitables;server=localhost;uid=root;pwd=");  
  3.   
  4. public View(string sTitle)  
  5. {  
  6. InitializeComponent();  
  7. try  
  8. {  
  9. DataSet ds = new DataSet();  
  10. string query;  
  11. p = new MySqlParameter("@no_order", MySqlDbType.String);  
  12. p.Value = sTitle;  
  13. 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";  
  14. MySqlDataAdapter dscmd = new MySqlDataAdapter(query, conn);  
  15. dscmd.SelectCommand.Parameters.Add(p);  
  16. dscmd.Fill(ds);  
  17. RPT cryds = new RPT();  
  18. cryds.SetDataSource(ds.Tables[0]);  
  19. crystalReportViewer1.ReportSource = cryds;  
  20. crystalReportViewer1.Refresh();  
  21. }  
  22. catch (Exception ex)  
  23. {  
  24. MessageBox.Show(ex.Message);  
  25. }  
  26. finally  
  27. {  
  28. conn.Close();  
  29. }  
  30. conn.Close();  
  31. }  

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

Brought to you by:

Answers (2)