繁体   English   中英

如何使用C#中的多个表填充数据集以将其发送到Crystal Report

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

伙计们,我在SQL Database有2张桌子,我想把它们放到我的Crystal Report中,我看了一些只谈论一张桌子的视频。

现在,我想要显示在水晶报表中的数据,就像我从Textbox输入数据时所需要的,这就是我的代码。

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

我想我自己解决问题。

我添加Table1.Id = Table2.Id ,代码就起作用了,并对App.config File进行了一些更改,它将变成这样

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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