asp.net - Unable to correctly save DateTime into SQL Server 2012 -
i have 2 controls taking input of date , time separately. namely txtdateoutgv
date , txtnewactiontimeoutgv
time in hh:mm tt
format time picker control.
i have tried many ways insert sql server 2012 database , have never been able save time. saved time 2014-10-04 00:00:00
what approach this? have tried using stored procedures , didn't work either.
dim stractiontimeout string = directcast(gvactions.footerrow.findcontrol("txtdateoutgv"), textbox).text + " " + convert.todatetime(request.form(directcast(gvactions.footerrow.findcontrol("txtnewactiontimeoutgv"), textbox).uniqueid)).tostring("hh:mm:ss") dim actiontimeout datetime actiontimeout = datetime.parseexact(stractiontimeout, "yyyy-mm-dd hh:mm:ss", cultureinfo.invariantculture) actiontimeout = format(convert.todatetime(stractiontimeout), "yyyy-mm-dd hh:mm:ss") insertaction string = "insert actions([timeout]) values ("+ convert(date, convert(datetime, '" + actiontimeout + "', 0), 120)" + ")"
the time format should converted in sql server too.. not sure if issue.
yes, code that:
convert(date, convert(datetime, '" + actiontimeout
you convert input value datetime (unnecessary) , date. last convert loose time info, expected.
use datetime parameter:
sqlcommand cmd = new sqlcommand("insert actions([timeout]) values (@actiontimeout);"); cmd.parameters.addwithvalue("@actiontimeout", actiontimeout); cmd.execute(...);
Comments
Post a Comment