c#
  • crystal-reports
  • 2013-05-17 87 views 0 likes 
    0

    我正在使用Crystal Report,但现在我遇到了问题。我正在使用visual studio 2010.Crystal Reports与SQL查询

    private void button1_Click(object sender, EventArgs e) 
        { 
         SqlCommand com = new SqlCommand("Select * from Students where StudentID='" + textBox1.Text + "'", conn); 
         adap.SelectCommand = com; 
         adap.Fill(tables); 
         CrystalReport1 myreport = new CrystalReport1(); 
         myreport.SetDataSource(tables); 
         crystalReportViewer1.ReportSource = myreport; 
        } 
    

    我写了这段代码,但它不起作用。我的意思是Crystal Report向我展示了数据库中的所有学生。我只想从文本框中选择StudentID。但它曾经在另一个项目上工作过。我打开新的项目一切都一样,但现在不工作。

    请帮帮我。

    回答

    1
    private void button1_Click(object sender, EventArgs e) 
        { 
         SqlCommand com = new SqlCommand("Select * from Students where StudentID='" + textBox1.Text + "'", conn); 
         adap.SelectCommand = com; 
         adap.Fill(tables); 
         ReportDocument doc; 
         CrystalReport1 myreport = new CrystalReport1(); 
         myreport.SetDataSource(tables); 
         doc = new ReportDocument(); 
         doc.Load(Server.MapPath("RptName.rpt")); 
         myreport.ReportSource = doc; 
         myreport.ReportSource = myreport; 
        } 
    
    相关问题