FormのコンボボックスSelectedIndexChangedでCrystalReportに値を渡して開く
@n_idは、SQLパラメーター
if (combobox1.SelectedItem == null) { // SelectedItemがない場合 da.SelectCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@n_id", System.Data.SqlDbType.Int, 4, "n_id")); } else { // SelecteItemがある場合 DataRowView row = (DataRowView)combobox1.SelectedItem; da.SelectCommand.Parameters.AddWithValue("n_id", row["n_id"]); // Create a CrUsers object CrCertificates myReport = new CrCertificates(); // Set the ParameterValue of the report string s = combobox1.Text; myReport.SetParameterValue(0, s); // Set the DataSource of the report myReport.SetDataSource(Newds); // Set the Report Source to ReportView CrvCertificates.ReportSource = myReport; }
あと、CrestalReportでパラメーターフィールドをn_idという名前で新規作成しておくのを忘れずに。
実は、ここがわかっていなくてしばし悩んだ。