c# - How to Use DateTime Web Form Field to Pass DateTime Parameter into Database using Stored Procedure? -
i trying use datetime field in webform pass datetime parameter database.
the datetime format in database is:
2015-05-18 00:00:00.000 the webform input field is:
<asp:textbox clientidmode="static" id="txteffdate" runat="server" cssclass="calendarimg" width="100px"></asp:textbox> <asp:imagebutton runat="server" id="imagebutton1" imageurl="~/images/cal.gif" borderstyle="none" alternatetext="click show calendar" tabindex="300" style="cursor: pointer;" width="16px" /> <asp:calendarextender id="calendarextender1" runat="server" targetcontrolid="txteffdate" popupbuttonid="imagebutton1" /> the specific parameter code behind is:
cmd.parameters.add("@desiredeffdate", sqldbtype.datetime).value = txteffdate; the specific parameter in stored procedure is:
@desiredeffdate datetime, how should define datetime correctly or convert proper format in code behind?
thanks help!
unless you're question has typo, tying set sql parameter value textbox object, rather value of textbox. should value of using txteffdate.text. assuming text box value can formatted date time (either date time picker or setting type attribute, latter doesn't have same browser compatibility former, @ time), should cast correctly date time in sql. can converted .net date time using function provided answer posted previously
Comments
Post a Comment