如何在报表查看器中的表中显示Sql Database中的数据

时间:2014-03-07 16:57:41

标签: c# reportviewer

我已经使用这些代码在我的表单中向DataGridView显示数据,现在我想在报表查看器中显示它。我怎么能这样做?

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

1 个答案:

答案 0 :(得分:1)