求救:DataGrid中的DateTime字段无法赋给DateTimePicker.Value??? newFrmChDz.dtpRegDate.Value = Convert.ToDateTime(this.dgZlgl[thisRowId, 5]) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this.dgZlgl[thisRowId, 5]在中断调试时发现是System.DateTime类型,为什么还要进行转换?我不知道原因。我着这么转换的:char[] separator = {' ', '-', '/', ':'};string[] dtString; dtString = this.dgZlgl[thisRowId, 5].ToString().Split(separator);int[] dtInt = new int[dtString.Length];int i = 0;foreach(string word in dtString){ dtInt[i++] = Convert.ToInt32(word);} newFrmChDz.dtpRegDate.Value = new DateTime(dtInt[0], dtInt[1], dtInt[2], dtInt[3], dtInt[4], dtInt[5]); newFrmChDz.dtpRegDate.Value = Convert.ToDateTime(this.dgZlgl[thisRowId, 5]); 可以,但既然都是System.DateTime类型,为什么要做转换呢?谢谢: qimini(循序渐进) newFrmChDz.dtpRegDate.Value = Convert.ToDateTime(this.dgZlgl[thisRowId, 5]); 在编译时出现错误提示,但程序运行正确,不知这是什么原因?Convert.ToDateTime(this.dgZlgl[thisRowId, 5]) 错误: 参数与函数Convert.ToDateTime”的参数不匹配 DateTime是一个Structure(一个值类型的数据),你可以隐式转换成引用类型(系统完成Box操作)this.dgZlgl[thisRowId, 5] = newFrmChDz.dtpRegDate.Value ;而DataTable的字段是Object(引用类型)newFrmChDz.dtpRegDate.Value = this.dgZlgl[thisRowId, 5]; 如果不做转换,你是不可以把一个引用类型的对象赋值给一个值类型的变量的~~~(系统不会自动进行Unbox操作)更详细的解释,你可以参考MSDN关于Box和UnBox的阐述希望能对你有所帮助~~~ 谢谢 qimini(循序渐进) !!! 请教一个Winform程序公共类的问题 很简单的treeview的问题 trvFtpFileTree_NodeMouseDoubleClick”的重载均与委托“System.Windows.Forms.TreeViewEventHa 百分求保存IE浏览记录的Index.dat文件对应的类结构 求助在一个子线程中重新启动主线程 在c#中如何添加一个菜单 如何在DataGridView显示List 原码请大家帮我看一下?帮我解决一下 asp.net(C#)项目经理 应该具备什么素质 侠哥哥,侠姐姐们,请问数据库的一个小问题 :) 请问怎么让程序重新加载一边呀? Assembly装配件问题
char[] separator = {' ', '-', '/', ':'};
string[] dtString;
dtString = this.dgZlgl[thisRowId, 5].ToString().Split(separator);
int[] dtInt = new int[dtString.Length];
int i = 0;
foreach(string word in dtString)
{
dtInt[i++] = Convert.ToInt32(word);
} newFrmChDz.dtpRegDate.Value = new DateTime(dtInt[0], dtInt[1], dtInt[2], dtInt[3], dtInt[4], dtInt[5]);
可以,但既然都是System.DateTime类型,为什么要做转换呢?
谢谢: qimini(循序渐进)
在编译时出现错误提示,但程序运行正确,不知这是什么原因?
Convert.ToDateTime(this.dgZlgl[thisRowId, 5]) 错误: 参数与函数Convert.ToDateTime”的参数不匹配
this.dgZlgl[thisRowId, 5] = newFrmChDz.dtpRegDate.Value ;
而DataTable的字段是Object(引用类型)
newFrmChDz.dtpRegDate.Value = this.dgZlgl[thisRowId, 5];
如果不做转换,你是不可以把一个引用类型的对象赋值给一个值类型的变量的~~~(系统不会自动进行Unbox操作)更详细的解释,你可以参考MSDN关于Box和UnBox的阐述
希望能对你有所帮助~~~