Making a DataSet Manually and then Fill a Report Viewer with the DataSet's result and using the report parameters- How?

  • Thread starter Thread starter F.oliveirarocha
  • Start date Start date
F

F.oliveirarocha

Guest
Hi folks, good evening for everyone, I'll need once again a help from you, to solve a small problem.

I'm doing a Form with 2 dates parameters (initial and final), but first I'm making a DataSet manually to fill the DataAdapter.

And after that, send the results for the Report Viewer. Everything works, no Errors or messages happens, but I don't get the data on my report Viewer file .rdlc, it opens blank, empty. How do I should send the database results to the report viewer manually?

Here goes my code:



private void btn_executar_Click(object sender, EventArgs e)
{
string constr = @"Data Source=DESKTOP-3O98051;Initial Catalog=SGFRenaissance;Integrated Security=True";
String queryString = @"SELECT Numero_Parcelas_a_Receber.Cod_Entrada_Titulos_a_Receber, Entrada_Titulos_a_Receber.Numero_NF, Entrada_Titulos_a_Receber.Data_NF, Numero_Parcelas_a_Receber.Data_Vencimento, Numero_Parcelas_a_Receber.Valor_Parcela, Entrada_Titulos_a_Receber.Cod_Cliente, Clientes_Contas_a_Receber.Nome_Cliente, Numero_Parcelas_a_Receber.Historico
FROM Numero_Parcelas_a_Receber
INNER JOIN Entrada_Titulos_a_Receber ON Entrada_Titulos_a_Receber.Cod_Entrada_Titulos_a_Receber = Numero_Parcelas_a_Receber.Cod_Entrada_Titulos_a_Receber
INNER JOIN Clientes_Contas_a_Receber ON Entrada_Titulos_a_Receber.Cod_Cliente = Clientes_Contas_a_Receber.Cod_Cliente_Contas_a_Receber";
// cmd = new SqlCommand(queryString, conn);

using (SqlConnection conn = new SqlConnection(constr))
{
try
{
conn.Open();
if (conn.State == ConnectionState.Open)
{
SqlDataAdapter dataAdapter = new SqlDataAdapter(queryString, conn);
DataSet dataSet_NF = new DataSet();
DataTable DT_NF_Opened = new DataTable();
dataAdapter.Fill(dataSet_NF, "DT_NF_Opened");
var dataView_NF = new DataView(DT_NF_Opened);
var dataSource_NF = new Microsoft.Reporting.WinForms.ReportDataSource("dataSet_NF", dataView_NF);
// Inserting and Filtering with Parameters
DateTime datainicio = Convert.ToDateTime(dateTimePicker_inicio.Text);
DateTime datafinal = Convert.ToDateTime(dateTimePicker_final.Text);
ReportParameter[] parameters = new ReportParameter[2];
parameters[0] = new ReportParameter("ReportParameter1", dateTimePicker_inicio.Text.ToString());
parameters[1] = new ReportParameter("ReportParameter2", dateTimePicker_final.Text.ToString());
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(dataSource_NF);
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("ReportParameter1", dateTimePicker_inicio.Text.ToString()));
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("ReportParameter2", dateTimePicker_final.Text.ToString()));
this.reportViewer1.RefreshReport();

}

}
catch (Exception EX)
{
MessageBox.Show("Erro ao Executar Consulta ao Banco de Dados! " + EX.Message);
}
finally
{
conn.Close();
}
}

}


The Result of queryString:

Cod_Entrada_Titulos_a_Receber Numero_NF Data_NF Data_Vencimento Valor_Parcela Cod_Cliente Nome_Cliente Historico
2036 52 2020-07-29 00:00:00.000 2020-08-31 27955.00 1007 Hospital Federal do Andaraí Material de Empenho Nº 2020NE800617
2057 60 2020-10-09 00:00:00.000 2020-11-09 81279.40 7 Hospital Federal de Bonsucesso Material de Empenho Nº 800855 - Entregue 09/10. HFB
2058 61 2020-10-19 00:00:00.000 2020-11-17 17060.00 7 Hospital Federal de Bonsucesso Nota Fiscal Material Trauma - Empenho 2020NE800333
2059 62 2020-10-19 00:00:00.000 2020-11-17 28883.50 7 Hospital Federal de Bonsucesso Nota Fiscal Material Trauma - Empenho 2020NE800855

Look the screen after execution:

1625084.jpg

Continue reading...
 
Back
Top