Ich muss für jeden Kunden eine PDF-Datei erstellen, die als Ergebnis einer Auswahl aus SQL-Abfrage kommt.Erstellen Sie ein PDF-Dokument für jeden Kunden in VB.net
Zum Beispiel für "Kunde 1" sollten alle Informationen dieses Kunden zu einer Datei namens "Customer1.pdf" gehen. Dann "Kunde 2" mit allen Informationen in "Customer2.pdf" usw. bis zum letzten Kunden aus der SQL-Abfrage.
Der Code funktioniert, das Problem ist die Schleife, um jedes Dokument für jeden Kunden zu erstellen: es erstellt nur ein Dokument mit allen Informationen.
Beispiel meines VB.net Code:
Dim customer_SQL As String
Using connObj As New SqlConnection(sql conection)
Using cmdObj As New SqlClient.SqlCommand("Select Distinct(customer_ID) from my table Where custmerid is not null", connObj)
connObj.Open()
Using readerObj As SqlClient.SqlDataReader = cmdObj.ExecuteReader
' This will loop through all returned records '
While readerObj.Read
Customer_SQL = readerObj("Customer_ID").ToString
' To see if it return the value I want
'MessageBox.Show(Customer_SQL.ToString)
Try
Dim CrExp As ExportOptions
Dim CrDiskFileDest As New DiskFileDestinationOptions()
Dim crFormatTypeopt As New PdfRtfWordFormatOptions()
For Li_count As Integer = 0 To Customer_SQL
CrDiskFileDest.DiskFileName = "C:\Report" & Customer_SQL.ToString & ".pdf"
CrExp = cryRpt.ExportOptions
With CrExp
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDest
.FormatOptions = crFormatTypeopt
End With
cryRpt.Export()
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End While
End Using
connObj.Close()
End Using
End Using
Danke Tim ... um es zu korrigieren – Luis64
Wenn Sie die angezeigten Probleme mit [Option Strict On] korrigieren (https://docs.microsoft.com/en-us/dotnet/articles/visual-basic/language-reference/ Statements/Option-Strict-Statement) haben Sie vielleicht ein Arbeitsprogramm. Außerdem ist "custmerid" in der SQL-Abfrage die richtige Schreibweise? –
Normalerweise würde ich den Inhalt des Codes nicht ändern, wenn ich sein Format bearbeite, aber die Zeile 'CmdObj As New SqlClient.SqlCommand (" Select Distinct (customer_ID) aus meiner Tabelle where candidmer ist nicht null, connObj) "fehlte ein essentielles Closing Ich nehme an, das war ein Übertragungsfehler –