I had my export working fine for what we needed it to do. Since then, a new piece of functionality needs to be added to it. Another SQL table was thrown into the mix(sitelist). The table only contains 2 columns. Site and File. I was able to join this table on my "KS" table by the site column. What I am wanting to do though is change my export to write separate files for each different sitelist.File. The sitelist table would looks like this:
Site1 FileA
Site2 FileA
Site3 FileB
Site4 FileB
I already have my dataset populated with each record to include on ALL export files, and they are grouped by sitelist.File
Here is my previous code that shows what I was doing to write to the file. What I am having problems with is getting it to break the files up by sitelist.File. So I want it to write all records with FileA into a file called FileA.txt - then move to all FileB records and write it to FileB.txt
Is this difficult to accomplish with what I already have?
Code:
Dim DBDataSet As New DataSet()
DBDataAdapter.Fill(DBDataSet, "t_groupdata")
Dim DBRow As DataRow
'Used to retrieve the field names
'Dim DBCol As DataColumn
Dim SWriter As New System.IO.StreamWriter("C:\Temp\test.txt")
'Dim strData As String
Dim pcDate As New DateTime(1971, 9, 27)
Dim ldShipDate As DateTime
For Each DBRow In DBDataSet.Tables("t_groupdata").Rows
SWriter.Write(DBRow("id") & ";")
ldShipDate = DBRow("shipdate")
Dim daysformatted As Integer = ldShipDate.ToOADate() - pcDate.ToOADate()
Dim finaldate As String
finaldate = daysformatted.ToString("#0-000")
SWriter.Write(finaldate & ";SALES;")
SWriter.Write(DBRow("head") & ";0;")
SWriter.Write(DBRow("weight") & ";;DIRECT;")
SWriter.Write(strPacker & NewLine)
SWriter.Write(DBRow("id") & ";")
SWriter.Write(finaldate & ";")
SWriter.Write("GENERAL;FLAG;")
SWriter.Write("ShipRptNo" & NewLine)
'Optional code used to remove the end of line semicolon
'strData = Mid(strData, 1, strData.Length - 1)
Next
'Close the new txt file.
SWriter.Close()
DBCon.Close()
Some of my variable are used later in my code that might not seem relevant to this piece, which it's not :-) This is just the write portion