Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!
Try sqlConnection.Open() sqlResults = sqlSelectCommand.ExecuteReader() Dim fNextResult As Boolean = True Using streamWriterObject As New StreamWriter(CSVFileandLocation) Do Until Not fNextResult streamWriterObject.WriteLine(sqlResults.GetName(0) & "," & FixNull(sqlResults.GetName(1)) & "," & FixNull(sqlResults.GetName(2))) 'Overwrite the original csv file with new records Do While (sqlResults.Read) streamWriterObject.WriteLine(sqlResults.GetString(0) & "," & FixNull(sqlResults.GetString(1)) & "," & FixNull(sqlResults.GetString(2))) Loop fNextResult = sqlResults.NextResult() Loop streamWriterObject.Close() sqlResults.Close() End Using Catch ex As Exception Console.WriteLine(ex.Message) MessageBox(ex.ToString) Finally sqlConnection.Close() End Try
Public Function FixNull(ByVal o As Object) As Object If IsDBNull(o) Then Return Nothing Else Return o End If End Function
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.