How to programmatically assign the date to a datetimepicker from a database in c# -
i hav datetimepicker control format have set custom dd/mm/yyyy (with no time). store date in database varchar , not datetime because giving sort of error regarding invalid datetime format. use datagrid display records database. thing need retrive date datagrid (when user selects particular date cell in datagrid) , want display on datetimepicker control (so user can edit it). using following code so: dtdate.value = convert.todatetime(dgdetails.selectedcells[1].formattedvalue);
the error getting "string not recognized valid datetime". dtdate datetimepicker control, dgdetails datagrid , selectedcells[1] cell containing date.
you shouldn't have reacted error changing type in database inappropriately - if you're trying store dates, should use closest available type in database.
the problem querying/updating/inserting putting value directly in sql instead of using parameterized query - right solution use parameterized query.
you've done same thing data grid, sounds of it. why bother parsing when can @ value without going via string representation? try:
dtdate.value = (datetime) dgdetails.selectedcells[1].value;
note wasn't assignment failing - call convert.todatetime
. (the stack trace should have shown this.)
Comments
Post a Comment