2
I need to pass data from DataGridView
to the ReportViewer
to make impression, but as I am still novice in c# I am not able to pass the datatable
to the form of ReportViewer
, if anyone can explain me a step by step I appreciate.
follows my code from DataGridView
private void bln_gerar_Click(object sender, EventArgs e)
{
try
{
SqlCommand geracomissao = new SqlCommand("usp_RelatorioComissao", conexaoDADOSADV(true));
geracomissao.Parameters.AddWithValue("@VENDEDOR", this.txt_vendedor.Text);
geracomissao.Parameters.AddWithValue("@DTINICIAL", this.txt_dtinicial.Text);
geracomissao.Parameters.AddWithValue("@DTFINAL", this.txt_dtfinal.Text);
geracomissao.CommandType = CommandType.StoredProcedure;
geracomissao.ExecuteNonQuery();
SqlDataAdapter dados = new SqlDataAdapter(geracomissao);
DataTable dtLista = new DataTable();
dados.Fill(dtLista);
dgw_comissao.DataSource = dtLista;
dgw_comissao.Columns["NOTA"].ReadOnly = true;
dgw_comissao.Columns["CLIENTE"].ReadOnly = true;
dgw_comissao.Columns["PRODUTO"].ReadOnly = true;
dgw_comissao.Columns["VALOR PARCELA"].ReadOnly = true;
dgw_comissao.Columns["PARCELA S/ IMPOSTO"].ReadOnly = true;
dgw_comissao.Columns["VENCIMENTO"].ReadOnly = true;
dgw_comissao.Columns["PREÇO VENDA"].ReadOnly = true;
dgw_comissao.Columns["COMISSÃO VENDEDOR"].Visible = false;
}
catch
{
MessageBox.Show("Não exstem dados digitados para a consulta, por favor verificar!!!");
return;
}
}
follows the code of the form where I am placing the ReportViewer
.
public partial class frmImpRelatorioComissao : Form
{
public frmImpRelatorioComissao()
{
InitializeComponent();
}
private void frmImpRelatorioComissao_Load(object sender, EventArgs e)
{
this.rpw_comissao.RefreshReport();
}
}
Ismael sorry my ignorance kk on this question, but as a parameter step my datatable which is in Form1..
– Junior Guerreiro
When do you open the report form? That is, when you give
new frmImpRelatorioComissao
?– Ismael
@Juniorguerreiro I updated the answer with a more practical way and also added an example of how to call the form.
– Ismael
Thank you so much for your help.
– Junior Guerreiro