简体   繁体   English

如何在报表查看器的表中显示来自Sql数据库的数据

[英]How to display data from Sql Database in table in report viewer

I already display data to a DataGridView in my form with these codes, now I want to display that in a report viewer. 我已经使用这些代码以表单的形式在DataGridView中显示数据,现在我想在报表查看器中显示数据。 How can I do this ? 我怎样才能做到这一点 ?

//Fill DataGridView
try
{
    MyDB db = new MyDB();//my connection string
    string sql = "SELECT * FROM innoviceitem WHERE id='{0}'";
    sql = string.Format(sql, id);//id is a public string that its value has been set
    SqlDataAdapter sda = new SqlDataAdapter(sql, db.MyConn);
    DataSet ds = new DataSet();
    BindingSource bs = new BindingSource();
    sda.Fill(ds);
    bs.DataSource = ds.Tables[0].DefaultView;
    datagridview1.DataSource = bs;
}
catch (Exception err) { MessageBox.Show(err.Message); }

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

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