修复winforms数据库导航器添加记录 [英] Fix winforms database navigator add record

查看:69
本文介绍了修复winforms数据库导航器添加记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含详细信息视图和数据网格的C#窗体。添加记录工作正常,但突然停止工作。正常工作时,单击添加按钮会将-1等插入ID字段,该字段设置为自动编号。现在数字无法显示,数据将不会保存回数据库。我可以输入一个数字,记录将保存。我使用MySql,使用Workbench时记录插入和自动编号工作正常。该表单是使用VS 2010专业版构建的,因此生成了大量代码。我在哪里寻找损坏的代码?我有一个类似的窗体连接到不同的数据库,它继续正常工作。

谢谢你的帮助。我真的不想从头开始重建表格。



我尝试了什么:



我寻找任何明显但没有成功的东西。我没有运气重建了表格。在没有运气的情况下从.net 4更改为3.5。

解决方案

永远不会向用户公开id字段。除非您的代码知道如何处理该值,否则它也应该没有-1。如果你要在表中添加记录,它就不应该有一个值,以便让数据库自己分配ID值。



至于哪里看,这完全取决于你的代码。我们看不到它,也对它一无所知,所以几乎不可能说出来。


我找到了答案。非常简单。使用Visual Studio数据集设计器,可以为每个列设置属性。感兴趣的属性是自动编号。不知怎的,我无意中把它设置为假。改为true,重新编译,一切都很好。恢复我对微软的信心。感谢。

I have a C# windows form containing a details view and a datagrid. Adding a record was working fine, but suddenly stopped working. When working properly, clicking the add button would insert -1, etc. into the ID field which is set to auto number. Now the number fails to appear and the data won't save back to the database. I can input a number and the record will save. I use MySql, and the record insert and auto-mumbering works fine when using Workbench. The form is built with VS 2010 professional, so there is lots of code generated. Where do I look for corrupt code? I have a similar windows form connecting to a different database and it continues to work properly.
Thank you for you help. I really don't want to rebuild the form from scratch.

What I have tried:

I looked for anything obvious with no success. And I rebuilt the form with no luck. Changed from .net 4 to 3.5 with no luck.

解决方案

The id field should never be exposed to the user. It should also not have a -1 in it unless your code knows what to do with that value. If you're adding records to the table, it shouldn't have a value at all in order to let the database assign the ID value itself.

As for where to look, that depends entirely on your code. We can't see it and know nothing about it so it's pretty much impossible to say.


I found the answer. Quite simple. With the Visual Studio dataset designer one can set properties for each of the columns. The property of interest is auto number. Somehow I inadvertently set it to false. Changed to true, recompiled, and all is well. Restoring my faith in Microsoft stuff. Thanks.


这篇关于修复winforms数据库导航器添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆