У меня есть 163 данных и привязка в stringbuilder и преобразование в pdf но показать только 162 данных последние данные не отображаются в pdf
Public Sub ShowMailingLabelsPDF() Using sw As New StringWriter() Using hw As New HtmlTextWriter(sw) Dim datStartDate As Date = calStartDate.SelectedDate Dim datEndDate As Date = calEndDate.SelectedDate Dim blnVisitsOnly As Boolean = cbxVisitsOnly.Checked Dim intLisintFileCount As Integer = 0 If datStartDate > datEndDate Then lblTestStatus.Text = "The start date must occur before the end date, please enter a valid start date." Exit Sub End If 'Retrieve Listing Data Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("BrokerLLCConnectionString1").ConnectionString.ToString) Dim cmd As New SqlCommand() If blnVisitsOnly = True Then cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '') AND (VisitDate >= '" & datStartDate & "' AND VisitDate <= '" & datEndDate & "')" cmd.Connection = conn Else cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '')" cmd.Connection = conn End If Dim dr As SqlDataReader = Nothing conn.Open() dr = cmd.ExecuteReader() Dim DT As New DataTable() DT.Load(dr) Dim sb As New StringBuilder() sb.Append("<html xmlns='http://www.w3.org/1999/xhtml'>") sb.Append("<head>") sb.Append("</head>") sb.Append("<body style=""font-family: Arial; color: #000000; font-size: medium;"">") sb.Append("<div style="" solid="">") sb.Append("<table style="">") 'Dim k As Integer = 0 For i As Integer = 0 To DT.Rows.Count - 1 'k += 1 If i = 0 OrElse i Mod 3 = 0 OrElse i = DT.Rows.Count - 1 Then sb.Append("<tr>") ' If i > 0 Then ' Else ' End If 'Else End If sb.Append("<td style="">") sb.Append("<table style="" valign="" top="">") sb.Append("<tr>") sb.Append("<td>") sb.Append("<p style="">") sb.Append(DT.Rows(i)("PrefixAbbrev").ToString() + " " + DT.Rows(i)("NameFirst").ToString() + " " + DT.Rows(i)("NameLast").ToString()) sb.Append("</p>") sb.Append("<p style="">") sb.Append(If(Convert.ToString(DT.Rows(i)("Address").ToString()), If("", "", Convert.ToString(DT.Rows(i)("Address").ToString())))) sb.Append("</p>") sb.Append("<p style="">") sb.Append(If(Convert.ToString(DT.Rows(i)("City").ToString()), If("", "", Convert.ToString(DT.Rows(i)("City").ToString())))) sb.Append(", ") sb.Append(If(Convert.ToString(DT.Rows(i)("State_ID").ToString()), If("", "", Convert.ToString(DT.Rows(i)("State_ID").ToString())))) sb.Append(", ") sb.Append(If(Convert.ToString(DT.Rows(i)("ZipCode").ToString()), If("", "", Convert.ToString(DT.Rows(i)("ZipCode").ToString())))) sb.Append("</p>") sb.Append("</td>") sb.Append("</tr>") sb.Append("</table>") sb.Append("</td>") If i Mod 3 = 2 OrElse i = DT.Rows.Count - 1 Then sb.Append("<br />") sb.Append("</tr>") 'k += 1 'If k = 10 Then ' Continue For 'End If End If 'If (i Mod 3) = 0 AndAlso i > 0 Then ' sb.Append("<br />") ' sb.Append("") 'End If Next sb.Append("</table>") sb.Append("</div>") sb.Append("</body>") sb.Append("</html>") Dim sr As New StringReader(sb.ToString()) Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "attachment;filename=ExportedClientDocument.pdf") Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim pdfDoc As New Document(PageSize.A4, 5, 3, 10, 70) Dim htmlparser As New HTMLWorker(pdfDoc) Dim pdfWriter__1 As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.Write(pdfDoc) End Using End Using End Sub
[edit]добавлен блок кода-OriginalGriff [/edit]
Что я уже пробовал:
это мой код, и проблема в том, что я не могу его найти. в stringbuilder данные 163 связываются, но при преобразовании в pdf отображаются только 162 данных. это срочно плз дайте мне какое нибудь решение
Richard Deeming
Ваш код уязвим для SQL-инъекция[^]. НИКОГДА используйте конкатенацию строк для построения SQL-запроса. ВСЕГДА используйте параметризованный запрос.
Все, что вы хотели знать о SQL-инъекции (но боялись спросить) | Трой Хант[^]
Как я могу объяснить SQL-инъекцию без технического жаргона? | Обмен Стеками Информационной Безопасности[^]
Шпаргалка по параметризации запросов / OWASP[^]