使用Databound TextBox插入记录(Windows窗体) [英] Insert records with Databound TextBox (Windows Forms)

查看:72
本文介绍了使用Databound TextBox插入记录(Windows窗体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道是否存在通过数据绑定控件将(新)记录插入到DataSet中的一般做法.

场景如下:我有一个dataGirdView,它显示记录列表和一些绑定到同一数据集的文本框,分别显示每个字段.

我可以编辑一条记录(使用文本框),然后调用dataSet.AcceptChanges(),但是,向数据集添加新行则是另一回事了.创建行后,我无法将数据集定位到该行,因此无法使用文本框填充数据字段.

也许我的问题是我试图采用这种德尔菲方式".非常感谢您的帮助!

谢谢大家,
blizzard

Hi all,

I''d like to know if there''s a general practice for inserting (new) records into a DataSet through databound controls.

The scenario is the following: I have a dataGirdView that displays a list of the records and some textboxes bound to the same dataset that display each field separately.

I can edit a record (using the textboxes) and then call dataSet.AcceptChanges(), however, adding a new row to the dataset is a different story. After I create the row I can''t position my dataset to it, therefore I can''t use the textboxes to populate the fields with data.

Maybe my problem is that I''m trying to approach this "the Delphi way". Any help is much appreciated!

Thank you all,
blizzard

推荐答案

我从不使用任何接受更改"废话.我编写了一个适当的数据层,并调用它来更新,插入或删除记录.据我所知,尽管可以创建编辑/插入模板,但是您无法数据绑定文本框.无论如何,如果模板允许我创建内联编辑或插入,我仍然希望编写自己的代码来调用我控制的数据层以进行插入.然后,只需将网格重新绑定到数据源,然后插入即可.
I NEVER use any of that ''accept changes'' crap. I write a proper data layer, and call it to update, insert or delete records. You can''t data bind a textbox, as far as I know, although you can create edit/insert templates. In any case, if the template lets me create inline editing or inserting, I''d still expect to write my own code to call a data layer I control to do the insert. Then, you just rebind the grid to the data source and your insertion will be there.


我同意CG,您需要了解并使用数据访问层(DAL),它是控制您的发展的根本.

我还要补充一点,您应该查看列表控件中的不编辑".我总是弹出任何CRUD操作的对话框,并且从不在列表控件中进行编辑.这使您可以完全控制数据,可以在对话框中使用绑定,管理任何默认值并确保将数据写入数据库.然后关闭对话框并重新加载列表.
I agree with CG, you need to understand and use a Data Access Layer (DAL), it is fundamental to controlling you development.

I would also add that you should look at NOT editing in a list control. I always pop a dialog for any CRUD operations and never edit within a list control. This gives you complete control of the data, you can use binding in the dialog, manage any defaults and insure the data is written to the database. Then close the dialog and and reload the list.


这篇关于使用Databound TextBox插入记录(Windows窗体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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