Suganda Suganda

Suganda Suganda

  • NA
  • 24
  • 10.9k

How to create crystal report with relation table in C#?

Mar 26 2018 12:38 AM
Hi, i have mysql database ( download mysql database in this link https://github.com/sgnd/csharp-sistempakar/blob/master/cs_sistempakar.sql )
 
My code work with one table, but if i run with multiple table not working.
 
code for get "code_diagnose" in datagridview (if cell click)
  1. public void dgvReport_CellClick(object sender, DataGridViewCellEventArgs e)  
  2. {  
  3.             DataGridViewRow row = dgvReport.CurrentRow;              
  4.             txtCode.Text = row.Cells["code_diagnose"].Value.ToString();  
  5. }  
code for display form reportviewer by "code_diagnose" in txtCode.text
  1. private void btnSave_Click(object sender, EventArgs e)  
  2. {  
  3.             String sTitle;  
  4.             sTitle = txtCode.Text;  
  5.             ReportViewer fReport = new ReportViewer(sTitle);  
  6.             fReport.Show();  
  7. }  
code for get crystalreport to reportviewer
  1. MySqlParameter p;  
  2. MySqlConnection conn = new MySqlConnection("database=cs_sistempakar;server=localhost;uid=root;pwd=");  
  3.   
  4. public ReportViewer(string sTitle)  
  5. {              
  6.     InitializeComponent();  
  7.     try
  8. {  
  9.     DataSet ds = new DataSet();  
  10.     string query;  
  11.     p = new MySqlParameter("@code_diagnose", MySqlDbType.String);  
  12.     p.Value = sTitle;  
  13.       query = "SELECT diagnose.code_diagnose, account.name_account, diagnose.cf, hypothesis.name_hypothesis, hypothesis.solution_hypothesis FROM diagnose LEFT JOIN hypothesis ON diagnose.code_hypothesis = hypothesis.code_hypothesis LEFT JOIN account ON diagnose.code_account = account.code_account where code_diagnose=@code_diagnose";  
  14.                 MySqlDataAdapter dscmd = new MySqlDataAdapter(query, conn);  
  15.                 dscmd.SelectCommand.Parameters.Add(p);  
  16.                 dscmd.Fill(ds);  
  17.                 RPT2 cryds = new RPT2();  
  18.                 cryds.SetDataSource(ds.Tables[0]);  
  19.                 RPTView.ReportSource = cryds;  
  20.                 RPTView.Refresh();  
  21.             }  
  22.             catch (Exception ex)  
  23.             {  
  24.                 MessageBox.Show(ex.Message);  
  25.             }  
  26.             finally  
  27.             {  
  28.                 conn.Close();  
  29.             }  
  30.             conn.Close();  
  31.         }  
This is my program: If i click code_diagnose=2 in datagridview and click button print
 
 
Crystal report display all data in table. Not display code_diagnose = 2. 
 
 
How to fix the code for display i select "code_diagnose" from multiple table (foreign key)?