将MSSQL时间值绑定到DateTimePicker [英] Bind MSSQL Time Value To DateTimePicker
问题描述
美好的一天所有!!!
我在MSSQL 2008中有一个表有一个时间(7)列(列名''Task_Time'')。
我正在拿表中的行并在DataGridView中显示它们。
当数据从数据库加载,它放在我项目的数据表中;其中我已将列''Task_Time''声明为TimeSpan。
用户点击一行并打开一个表单,加载所选行的值。
当我试图将行数据加载到表单中时,我遇到了问题。我正在使用DateTimePicker来显示时间。我将DateTimePicker格式设置为time并将showupdown设置为true。但是我一直收到以下错误:
无法将值格式化为所需类型...
我做错了什么???
Good day all!!!
I have table in MSSQL 2008 that has a time(7) column (column name ''Task_Time'').
I''m taking the rows in the table and displaying them in a DataGridView.
When the data is loaded from the database it is placed in a datatable in my project; in which I have declared the column ''Task_Time'' as TimeSpan.
The user clicks on a row and it opens a form that loads the values of the row selected.
My problems comes when I''m trying to load the row data into the form. I''m using a DateTimePicker to display the time. I have DateTimePicker format set to time and showupdown set to true. But I keep getting the following error:
"Cannot format the value to the desired type"...
What am I doing wrong???
推荐答案
我将数据库中的列类型和数据表更改为DateTime。解决了这个问题。
然后我只是将DataGridViewColumn格式化为仅显示时间。
I changed the column type in the database and datatable to DateTime. that solved the problem.
Then I just format the DataGridViewColumn to display time only.
这篇关于将MSSQL时间值绑定到DateTimePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!