我在带有报告查看器的Windows窗体中有一个名为“Relatorio1.rdlc”的报告。
在VS Studio中构建时,代码没有错误
SqlConnection conec1 = Tconex.GetConnection();
private void Verrelatorio_Load(object sender, EventArgs e)
{
SqlCommand cmdReport = new SqlCommand();
SqlDataReader drreport;
DataSet dsreport = new dsBairros();
try
{
cmdReport.CommandType = CommandType.Text;
cmdReport.Connection = conec1;
cmdReport.CommandText = "select Codigo,descricao from tblBairros ";
drreport = cmdReport.ExecuteReader();
dsreport.Tables[0].Load(drreport);
drreport.Close();
reportViewer1.LocalReport.ReportEmbeddedResource = "ContaTroco.Relatorio1.rdlc";
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsBairros";
rds.Value = dsreport.Tables[0];
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conec1.State == ConnectionState.Open)
{ conec1.Close(); }
}
}
ReportViewer向我显示了Codigo字段的名称,描述但没有向我显示任何数据。
Dsbairros是一个类型化的数据集。我需要这样做,因为我将数据源的原始连接更改为不更新,现在报告不起作用。