neizen_is
neizen_is

Reputation: 39

Crystal Reports with SQL queries

I am working with Crystal Report but I have problem now. I am using visual studio 2010.

    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;
    }

I wrote this codes but it doesn't work. I mean Crystal Report shows me all students from the database. I want only specific studet with StudentID from textbox. But it worked once on another project. I open new project everything same but doesn't work now.

Please help me.

Upvotes: 2

Views: 5460

Answers (1)

Chetan Sanghani
Chetan Sanghani

Reputation: 2111

   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;
    }

Upvotes: 2

Related Questions