How to convert a "Date" type array to a "String" type array (VB)

My Code:

listDates = (From row In ds.Tables(0) Select row.Field(Of Date)("Check In")).ToList
arrDates = listDates.ToArray
        
  For a = 0 To arrDates.Length - 1
     arrDatesStr(a) = (arrDates(a)).ToString
  Next

I am making an analytics form to find the most popular month for a hotel:

  • listDates is a list that stores all of the dates from the database
  • arrDates is the conversion of listDates to an array
  • arrDatesStr is the array I need to fill with the date values but as strings, so i can substring the month

I have checked the values in listDates and arrDates and they conversion is successful, but when I try to convert it to string it says

"System.NullReferenceException: 'Object reference not set to an instance of an object.'"

How do I convert arrDates to a string and input those values into arrDatesStr?



Read more here: https://stackoverflow.com/questions/67373761/how-to-convert-a-date-type-array-to-a-string-type-array-vb

Content Attribution

This content was originally published by Oliwier at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: