sql - Error converting data type varchar to datetime using GETDATE() -
i realise quite common problem banded around forums, @ loss i've done wrong here.
i have 'current' table like:
id(uniqueidentifier) name(nvarchar max) filename(nvarchar max) fileversion(smallint) currentversiondate(datetime)
the currentversiondate entered using getdate() function within sqlserver.
when user hit's 'create file' on website, details of table transferred 'history' table. use stored procedure select * details 'current' , save each value variable (i'm using vb.net in visual studio project). i'll show date variable problem. i'm saving 'date' variable:
dim ddate date ddate = dr("currentversiondate")
then send these variables stored procedure enter 'history' table:
execute sp_inserthistory '" & id & "','" & strname& "','" & strfile & "','" & intversion & "','" & ddate & "'"
i declare date variable in stored procedure as:
@date datetime,
with insert statement:
insert history (id, name, filename, fileversion, versiondate) values (@id, @name, @filename, @fileversion, @date)
the 'history' table has same setup 'current' table. stepping through code, error caught:
error converting data type varchar datetime
surely variables isn't varchar? , if is, string surely in correct format sqlserver because i'm selecting date value sql has given! thoughts?
since putting date between quotes, varchar '" & ddate & "'"
, think problem have conversion retrieving date in local format , have insert date in sql server in own format.
try inserting date string in format: ddate.tostring("mm/dd/yyyy hh:mm:ss")
Comments
Post a Comment