正致力于报告申请。 经过一些学习后,我可以使用Crystal Report从数据库生成报告。 但是当第二张发票或账单的报告进入我的记录时,水晶报告显示没有记录,而记录存在于数据库中。
GRIDVIEW DATA
<asp:GridView ID="GridView1" DataKeyNames="billid" runat="server" AutoGenerateColumns="False" CellPadding="4" CssClass="mydatagrid"
PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" OnRowCommand="GridView1_RowCommand"
DataSourceID="Bill_View_Data" GridLines="None" AllowPaging="True">
<Columns>
<asp:BoundField DataField="billid" HeaderText="Bill No." SortExpression="billid" />
<asp:BoundField DataField="billdate" HeaderText="Bill Date" SortExpression="billdate" DataFormatString="{0:dd/MM/yyyy}" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="TOTAL" HeaderText="Total Amount" SortExpression="TOTAL" ReadOnly="True" />
<asp:TemplateField HeaderText="Print" ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" CommandName="Select"
CommandArgument="<%# Container.DataItemIndex %>" ImageUrl="~/App_Themes/images/Printer.png" Text="Print" />
</ItemTemplate>
<ControlStyle Height="24px" Width="24px" />
<ItemStyle Height="24px" Width="128px" />
</asp:TemplateField>
<asp:ButtonField HeaderText="E-mail" Text="E-mail">
</asp:ButtonField>
</Columns>
<HeaderStyle CssClass="header"></HeaderStyle>
<PagerStyle CssClass="pager"></PagerStyle>
<RowStyle CssClass="rows"></RowStyle>
</asp:GridView>
在gridview中显示数据后。数据如下图所示。 单击第1行打印按钮时,报告显示正确。 但是当涉及第二和第三时它显示报告空白。
获取数据和重定向到水晶报告的代码是
Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim selectedRow As GridViewRow = GridView1.Rows(index)
Dim contactCell As TableCell = selectedRow.Cells(0)
Dim contact As String = contactcell.Text
Session("BallID") = contact
Session("ContraxtID") = aggrmnt.SelectedValue
Response.Redirect("~/Infinity/rpt/report.aspx")
End If
End Sub
Report.ASPX页码
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim crystalReport As New ReportDocument()
crystalReport.Load(Server.MapPath("CrystalReport.rpt"))
Dim dsCustomers As RepoerDS = GetData()
crystalReport.SetDataSource(dsCustomers)
CrystalReportViewer1.ReportSource = crystalReport
End Sub
Private Function GetData() As RepoerDS
Dim conString As String = ConfigurationManager.ConnectionStrings("iNSbill").ConnectionString
Dim cmd As New SqlCommand()
Using con As New SqlConnection(conString)
Using sda As New SqlDataAdapter()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "bill"
cmd.Parameters.Add("@Company_Filter", SqlDbType.Int).Value = Session("Companydetl")
cmd.Parameters.Add("@Bill_Identification", SqlDbType.Int).Value = Session("BallID")
cmd.Parameters.Add("@ContraxtID", SqlDbType.Int).Value = Session("ContraxtID")
sda.SelectCommand = cmd
Using dsCustomers As New RepoerDS()
sda.Fill(dsCustomers, "Bill_Report")
Return dsCustomers
End Using
End Using
End Using
End Function