Avoid SQL Injection. There is no excuse as this was discovered over 20 years ago. Basically you need to drop a placeholder into the original query and add a parameter for that placeholder to the command object
AND (TabPrikazMzdyAZmetky.DatPorizeni<@Label1)
and
Dim cmd = New SqlCommand(SqlCommand, conn)
cmd.Parameters.AddWithValue("@Label1", Label1.Text)
file does not like as it should.
It looks like your first column may be written twice
StreamWriterObj.Write(Reader.Item(0))
For i As Integer = 0 To FieldCount - 1
StreamWriterObj.Write(Delimiter)
StreamWriterObj.Write(Reader.Item(i))
... and missing headers
Only 2 problems with this; CSV files actually do not have headers, but are typically just the first line written into the text file- the problem is that you never write that line to the file. Easy fix; before you go throught the loop of all the values, run your
For i
loop across the reader and use the
GetName(i)
property for each column