Writing an ItemArray that contains NULLS

Viewed 23

I'm trying to write a datarow out to a text file with delimiters between each value and this works fine until the SQL Table has any NULLs in it.

I can possibly just remove the NULL values from the table and block any new rows being able to have NULL and just have empty strings instead but wondered if there was a neater way to replace the NULL without having to loop through each column.

Currently I just use a JOIN (in VB.NET) to link all the values with my delimiter to create a string and then write out to a text file. I tried adding .ToString or using a Replace but neither managed to stop an exception

        Using objTextFile As New StreamWriter(Path.Combine(strTextFilePath, strTextFileName), False) 
            For Each setting As DataRow In recipeDataSet.Tables(0).Rows
               objTextFile.WriteLine(Join(setting.ItemArray, "|"))
            Next
            objTextFile.Flush()
            objTextFile.Close()
            objTextFile.Dispose()
        End Using
0 Answers
Related