c# - conversion of a varchar data type to a datetime data type resulted in an out-of-range value executing stored procedure -
i have problem error title. error ocures when try execute stored procedure this:
create procedure [dbo].[inserttimedate] @tablename nvarchar(28), @timestamp datetime, declare @query nvarchar(max); begin set @query = 'insert [' +@tablename+'] (timestamp) values ('''+convert(nvarchar, @timestamp, 20)+''')' exec (@query) end
i execute c# code:
dbcommand = new sqlcommand("inserttimedate", dbconnection); dbcommand.commandtype = commandtype.storedprocedure; dbcommand.parameters.addwithvalue("@tablename", "table_name"); dbcommand.parameters.addwithvalue("@timestamp", datetime.now); dbcommand.executenonquery();
try style 126 in convert - that's iso-8601 format should work language/regional setting of sql server:
set @query = 'insert [' +@tablename+'] (timestamp) values (''' + convert(nvarchar, @timestamp, 126) + ''')' exec (@query)
Comments
Post a Comment