I get this error
The types of the parameter field and parameter field current values are not compatible.
when passing both database and parameter to Crystal Reports.
ReportDocument rd = new ReportDocument();
public string user;
public frmReport(string User)
{
InitializeComponent();
loadReport();
this.user = User;
}
public void loadReport()
{
rd.Load(@"C:\Users\Jeff Enad\Desktop\TEST1\Cebu Hallmark Hotel Management System\Cebu Hallmark Hotel Management System\cryReport.rpt");
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=dbCebuHallmark;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("GetAllReport", con);
rd.SetParameterValue("UserPrinted", user); //This is the parameter
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "REPORT");
rd.SetDataSource(ds);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.Refresh();
}
The SetParameterValue()
is causing the error.
Can anyone help me to solve this problem? Should I add parameter in stored procedure or in dataset?
I just want to pass the user's name to the Crystal Report that has database.
You have to set the parameter and value in SqlCommand
object in your SqlAdapter
. Please see below for the updated code:
public void loadReport()
{
rd.Load(@"C:\Users\Jeff Enad\Desktop\TEST1\Cebu Hallmark Hotel Management System\Cebu Hallmark Hotel Management System\cryReport.rpt");
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=dbCebuHallmark;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("GetAllReport", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "REPORT");
rd.SetDataSource(ds);
rd.SetParameterValue("UserPrinted", user); //This is the parameter
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.Refresh();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.