自动生成列空值
我想将空值保存到 wpf 数据网格(带有自动生成列)上的小数列(允许数据库上有空值)。
它不允许我保存空值并显示红色错误框。
I want to save null values to a decimal column(allows nulls on db) on a wpf datagrid (with autogenerate columns).
It doesn't allow me to save nulls and shows red error box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑您遇到了我遇到的问题,但它是一个简单的文本框(不是数据网格)。您认为您传递的是 null,但实际上传递的是 string.empty,它既不是 null 也不是小数。我用转换器修复了它,将 string.empty 转换为 null。编辑你的问题的HB(同一个HB)回答了我的问题。
无法将 Null 值分配给可为 Null 的 Int32?通过绑定
I suspect you are running into a problem that I had but it was a simple text box (not a datagrid). You think you are passing a null but you are really passing string.empty which is neither null nor a decimal. I fixed it with a converter to convert string.empty to null. H.B. (the same H.B.) that edited your question answered mine.
Cannot Assign a Null Value to a Nullable Int32? via Binding
您将数据网格绑定到哪种数据库?例如,如果您使用 ado.net 将其绑定到数据表,则数据表不知道底层的 SQL 架构,除非您自己更新它。 -->请参阅http://support.microsoft.com/kb/310128
使用 linq2sql 它应该可以在没有此更新的情况下正常工作,而对于其他像 MySql 我不知道的。
to which kind of database are you binding your datagrid to ? for instance if you bind it to a datatable with ado.net, the datatable is not aware of the underlying sql schema unless you update it yourself. --> see http://support.microsoft.com/kb/310128
with linq2sql it should work fine without this update, with others like MySql i don't know.
只需在 AutogenerateColumn 事件中添加以下代码:
Just add this code in AutogeneratingColumn event: