且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试动态访问表单字段名称

更新时间:2023-02-19 07:40:33

此处要做的是构建一个名为"txt" +值的字符串,然后用退出阅读器的内容覆盖该字符串.

您不能将字符串转换为字段"对象.

除非这里有某些驱动程序阻止您这样做,否则为什么不遍历窗体上的控件集合呢?

对于表单中的每个控件,将其强制转换为文本框并检查是否为空.如果不为null,则检查名称是否包含数据库字段(或等于"txt" +字段名称),然后设置text属性.

一小段代码:

What you are doing here is building a string called "txt" + value and then overwriting that string with what you pull out of the reader.

You can''t convert a string to a "field" object.

Unless there is some driver here that prevents you from doing so, why not loop through the collection of controls on the form?

For each of the controls in the form, cast it to a textbox and check for null. If not null, then check to see if the name contains the database field (or if it equals "txt" + field name) and then set the text property.

a snippet of code:

For Each ctl In frm.Controls
 ' ...
Next ctl



现在,ctl是一个控件(如果需要的话,是一个字段对象),您可以检查它是否是文本框,然后在其上设置文本.

干杯.



Now, ctl is a control (a field object, if you will) and you can check to see if it is a textbox and then set the text on it.

Cheers.