2017-03-04 35 views
-1

我的代碼如下如何解決C#錯誤「了條件,預計將在指定的上下文非布爾類型的表達式,接近「

public partial class ProductWiseReportViewer : Form 
    { 
     SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=StockSF;Integrated Security=True"); 
     ReportDocument crypt = new ReportDocument(); 
     public ProductWiseReportViewer() 
     { 
      InitializeComponent(); 
     } 

     public DateTime date1 { get; set; } 

     public DateTime date2 { get; set; } 

     public object prname { get; set; } 

     private void crystalReportViewer1_Load(object sender, EventArgs e) 
     { 
      //this.reportViewer1.RefreshReport(); 
      SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM tblPurchase WHERE Pur_Date between '" + date1 + "'and '" + date2 + "'and'"+prname+"'",con); 
      DataTable dt = new DataTable(); 
      DataSet dst = new DataSet(); 
      sda.Fill(dst, "tblPurchase"); 
      crypt.Load(@"F:\Project C#\StockSF\StockSF\RptPurchase.rpt"); 
      crypt.SetDataSource(dst); 
      crystalReportViewer1.ReportSource = crypt; 
     } 
    } 
+0

什麼是 'X' 和 'Y' 和「z''平均值之間'Pur_Date? –

+0

請注意,不要像這樣構建SQL,**使用參數**。 –

回答

0

您在代碼中有這樣的:

and'"+prname+"'" 

這也許應該是這樣的

and PRNAME = '" + prname + "'" 
相關問題