anthony levano anthony levano - 1 month ago 9x Question

try to convert date to string in visual basic .net

I want to convert a date value to string in, but its not working
heres my code in when try to convert to string

While (sqlReader.Read())
pro.fechaOperacion = Convert.ToString(sqlReader.GetString(3))
end while

and this is my code for my stored proc

select ...
Convert (date, EN.FECHA,103),
...from Fact

Please I need your help.


You will run into unnecessary complications if you use strings for dates in your code. The only times you normally need to convert between the two are for input and output.

You can modify your code (as shown) to achieve that:

  • make pro.fechaOperacion a DateTime instead of a String.
  • select it value with SELECT ... [date] ... FROM Fact*.
  • retrieve its value with pro.fechaOperacion = sqlReader.GetDateTime(3).

* Use the appropriate delimiters for your database if `[` and `]` are wrong.