conversion from string yyyyMMdd to type integer is not valid

[亡魂溺海] 提交于 2020-01-23 13:15:47

问题


I have a dataset containing a datatable, and I enumerate all rows in that datatable. When trying to format a column in that row, I run into an exception. (Part of) the code is:

For Each dr As DataRow In ds.Tables("records").Rows
    file = dr("timestamp").ToString("yyyyMMdd") & "~.wav"
Next

This results in the following error message:

Conversion from string yyyyMMdd to type Integer is not valid. (translated from a Dutch error message to the English equivalent)

dr("timestamp").GetType.FullName results in "System.DateTime", so I don't understand why I run into this exception, as for example Now.ToString("yyyyMMdd") results in "20091002", and "Now" is of the same type as dr("timestamp"), "System.DateTime" that is.


回答1:


Try

For Each dr As DataRow In ds.Tables("records").Rows
    file = CDate(dr("timestamp")).ToString("yyyyMMdd") & "~.wav"
Next



回答2:


Have you made sure that you are not declaring the variable 'file' as an integer?



来源:https://stackoverflow.com/questions/1508566/conversion-from-string-yyyymmdd-to-type-integer-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!