在.csv文件中显示数据集中的所有记录

时间:2012-09-01 21:37:33

标签: sql vb.net datatable dataset

我有一个运行查询的VB.net程序。该查询将在时间上拉出数千条记录中的10条。截至目前,我已将查询报告给reportviewer,然后我在表单上有第二个按钮,将数据集导出到.csv文件。这一切都与广告一样,但它不显示所有记录。如果我在没有将信息存储在数据集中的情况下运行查询,我将获得超过1,000个结果。

当我运行该程序时,我只得到568个结果。我的假设是,使用程序中的“填充”命令,此信息太大。如何更改它以在报告查看器中或在选择“导出”按钮时显示数据集中的所有记录。

这是我的问题:

SELECT        Invoice_Tb.Customer_First_Name AS firstname, Invoice_Tb.Customer_Last_Name AS lastname, Invoice_Tb.Customer_Address AS add1, Invoice_Tb.City, 
                         Invoice_Tb.Customer_State AS State, LEFT(Invoice_Tb.ZIP_Code, 5) AS ZIP, Invoice_Tb.Customer_Email_Address AS [Email Address], 
                         Invoice_Tb.Vehicle_Mileage AS [Vehicle Mileage], Invoice_Tb.Invoice_Date AS [Date Of Service], Invoice_Tb.Store_Number, @startdate AS Start_Date, 
                         @enddate AS End_Date
FROM            Invoice_Detail_Tb INNER JOIN
                         Invoice_Tb ON Invoice_Detail_Tb.Invoice_Number = Invoice_Tb.Invoice_Number AND Invoice_Detail_Tb.Invoice_Date = Invoice_Tb.Invoice_Date
WHERE        (Invoice_Detail_Tb.Store_Category_Code = 'FS') AND (Invoice_Tb.Invoice_Date BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(Datetime, 
                         @enddate, 102)) AND (Invoice_Tb.Reminder_Mail_Flag = 'Y')

这是我的按钮代码,用于将结果提取到报告查看器:

Me.Invoice_TbTableAdapter.Fill(Me.DataDeliveryServiceDataSet.Invoice_Tb, startdatepicker.Value, enddatepicker.Value)


        Me.ReportViewer1.RefreshReport()

这是我的“导出”到csv按钮代码:

Dim str As New StringBuilder

        For Each dr As DataRow In Me.DataDeliveryServiceDataSet.Invoice_Tb

            For Each field As Object In dr.ItemArray

                str.Append(field.ToString & ",")

            Next

            str.Replace(",", vbNewLine, str.Length - 1, 1)

        Next



        Try

            My.Computer.FileSystem.WriteAllText("C:\temp\testcsv.csv", str.ToString, False)

        Catch ex As Exception

            MessageBox.Show("Write Error")

        End Try

知道如何才能显示所有记录吗?

0 个答案:

没有答案