Reusing some code found on the net requires understanding it.
The first thing to do before writing (or copying) any code is becoming familiar with the data to be processed. In your case these are
SQL Server Compact - Wikipedia[
^] and
Comma-separated values - Wikipedia[
^].
For the latter your code looks basically fine besides the missing quote support (fields containing a line-break, double-quote or the delimiting character should be quoted and double quotes in fields must be escaped with another double quote).
But it will never work because your
rdr
is
null
.
You have to know how to access SDF files using a
DataReader
. That is covered by the documentation of the used classes like
SqlCeDataReader Class (System.Data.SqlServerCe)[
^] which contains also example code.
Finally, you have to use SQL statements that apply to your database file. That is, you have to know the name(s) of the table(s) you want to export to CSV file(s) and the SQL syntax to query data from a table.