简体   繁体   中英

How to fill DataSet with multiple tables in c# to send it to Crystal Report

Guys I have 2 tables in SQL Database and I want bring them to my Crystal Report I watched some videos that talking about just one table.

Now I want my Data that Displayed in crystal report just I want it when I enter the Data from Textbox this is my codes.

private void butSearchByTextbox_Click(object sender, EventArgs e)
    {

        SqlConnection cn = new SqlConnection(@"Server=. ; DataBase=WaterProject; Integrated Security = true");
        SqlDataAdapter da = new SqlDataAdapter(" SELECT Table1.data , Table2.data FROM Table2 INNER JOIN Table1 ON Table1.Name Like '" + textBox1.Text + "'", cn);
        DataSet ds = new DataSet();
        da.Fill(ds, "Info");
        SubscriberData CryRep = new SubscriberData();
        CryRep.SetDataSource(ds.Tables["Table1"]); // I want multi tables
        crystalReportViewer1.ReportSource = CryRep;
    }

I think I solve my case with my self.

The code is working just I add Table1.Id = Table2.Id , And I make some change for App.config File It will became like this

 <startup  useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM