如何设置VB文本框允许为空?

如果要通过将信息填入文本框,向Access表中添加一条数据,但可以允许某些文本框(即表中的某些列为空),应该怎么做呢?现在是这样:
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("设备类别") = Text1.Text
Adodc1.Recordset.Fields("设备名称") = Text2.Text
Adodc1.Recordset.Fields("设备编号") = Text3.Text
Adodc1.Recordset.Fields("数量") = Text4.Text
Adodc1.Recordset.Fields("单价") = Text5.Text
Adodc1.Recordset.Fields("生产厂家") = Text6.Text
Adodc1.Recordset.Fields("购买日期") = DT1.Value
Adodc1.Recordset.Fields("主要性能指标") = Text8.Text
Adodc1.Recordset.Fields("保管人") = Text9.Text
Adodc1.Recordset.Fields("经费来源") = Text10.Text
Adodc1.Recordset.Update
但是只有将所有的文本框内容都填进去,才能成功添加。

数据保存是否允许为空,在数据库各字段的属性里设置。

TextBox的内容为String资料形态包含VbNullString空字串,如果在数据库的字段属性为整数或单、双精度浮点型,赋值时就要使用转换函数赋值,比如
Adodc1.Recordset.Fields("数量") = CLng(Val(Text4.Text))
Adodc1.Recordset.Fields("单价") = CSng(Val(Text5.Text)) '或CDbl(Val(Text5.Text))
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-05-04
这是ado控件的问题,每个字段都要求参数。可以这样改:
Adodc1.Recordset.Fields("设备类别") =iif(len(Text1.Text)=0," ",Text1.Text)本回答被提问者采纳