anthony levano anthony levano - 2 months ago 16
Vb.net Question

try to convert date to string in visual basic .net

I want to convert a date value to string in vb.net, but its not working
heres my code in vb.net 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.

Answer

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.