Hi, I have a webform project in asp .net with c #, and in it I have an sql query to show data from several tables in a gridview (I did not put the complete sql query because it is a lot and it is from my work), and I want to export that table to a crystal report by clicking on a button.
But when I run my project and click on the button, nothing is displayed or displayed.
Here I leave my code:
webform1.aspx
<emptydatatemplate>
¡No se encontraron reportes!
</emptydatatemplate>
<Columns>
<%--campos...--%>
<asp:BoundField DataField="campo1" HeaderText="campo1" ReadOnly="True" SortExpression="campo1" />
webform1.aspx.cs
--- so I fill my gridview ---
SqlConnection with = new SqlConnection (ConfigurationManager.ConnectionStrings ["cn"]. ToString ()); con.Open (); SqlCommand cmd = new SqlCommand ("SELECT * from table where cod = '" + Session ["Cod_user"] + "', with); SqlDataAdapter da = new SqlDataAdapter (cmd); DataTable dt = new DataTable (); da.Fill (dt); grid1.Visible = true; grid1.DataSource = dt; grid1.DataBind ();
--- button_click see report -
DsRF ds = new DsRF (); // DsRF is the name of the dataset DataTable dt_RF = new DataTable (); dt_RF.Columns.Add ("column1", typeof (string)); --- more columns ----
// Passing the grid data to the dataset (this is not right)
for (int fila = 0; fila <grid1.Rows.Count - 1; fila++)
{
for (int col = 0; col < grid1.Rows[fila].Cells.Count; col++)
{
dt_RF.Rows.Add(grid1.Rows[fila].Cells[col].Text);
}
}
// show the dataset in the crystalview
ReportDocument oRep = new ReportDocument();
oRep.Load(Server.MapPath("~/Proyecto/myreporte.rpt"));
oRep.SetDataSource(ds);
CrystalReportViewer1.ReportSource = oRep;
I hope someone can help me
Thanks
Greetings