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)
- public void dgvReport_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- DataGridViewRow row = dgvReport.CurrentRow;
- txtCode.Text = row.Cells["code_diagnose"].Value.ToString();
- }
code for display form reportviewer by "code_diagnose" in txtCode.text
- private void btnSave_Click(object sender, EventArgs e)
- {
- String sTitle;
- sTitle = txtCode.Text;
- ReportViewer fReport = new ReportViewer(sTitle);
- fReport.Show();
- }
code for get crystalreport to reportviewer
- MySqlParameter p;
- MySqlConnection conn = new MySqlConnection("database=cs_sistempakar;server=localhost;uid=root;pwd=");
-
- public ReportViewer(string sTitle)
- {
- InitializeComponent();
- try
- {
- DataSet ds = new DataSet();
- string query;
- p = new MySqlParameter("@code_diagnose", MySqlDbType.String);
- p.Value = sTitle;
- 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";
- MySqlDataAdapter dscmd = new MySqlDataAdapter(query, conn);
- dscmd.SelectCommand.Parameters.Add(p);
- dscmd.Fill(ds);
- RPT2 cryds = new RPT2();
- cryds.SetDataSource(ds.Tables[0]);
- RPTView.ReportSource = cryds;
- RPTView.Refresh();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- conn.Close();
- }
- conn.Close();
- }
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)?