我正在写一个程序,其中有写字段的值可以为空如下:
create table student_info
(  studnet_id int not null primary key,
studnet_name char(10) null,
.....                 null
comment varchar(200) null,
)
当comment或其他字段的值为空时,出错text不能接受null
dim rs as adodb.recordset
strsql="select * from student_info"
rs.open strsql.........
text1.text=rs.fields(....)
text2.text=rs.fields(...)
....
textn.text=rs.fields(comment)
难道每个字段都要判断一下NULL再赋值吗?(如果有30个字段)有没有更好的办法(字段必须可以为空)

解决方案 »

  1.   

    可以考虑写一个共同函数
    把所有的值to text
    这样一来就不用考虑字段多少的问题
    例如:toText(rs.fields("字段名").value)
      

  2.   

    toText(rs.fields("字段名").value)
    没有totext的含义
    小弟学浅,能否详细赐教
      

  3.   

    text1.text=iif(isnull(rs.fields(....)),"",rs.fields(....))
      

  4.   

    text1.text=rs.fields(....) & " "
      

  5.   

    betagain(象草一样不能自拔) 的正确,用ISNULL函数判断就ok了
      

  6.   

    用控件数组:
    rs.open strsql.........
    FOR I=0 TO 30
    text1(I).text=rs.fields(I).VALUE &""
    NEXT
      

  7.   

    if not isnull(rs.fields(...)) then
       text1.text=rs.fields(...)
    end if
      

  8.   

    直接用下面语句就可以解决问题:
    text1.text=trim(rs.fields(字段) & "")
      

  9.   

    text1.text=trim(rs.fields(字段).value & "空格")
      

  10.   

    改为这样保准不出错。
    dim rs as adodb.recordset
    strsql="select * from student_info"
    rs.open strsql.........
    on error resume next
    text1.text=rs.fields(....)
    text2.text=rs.fields(...)
    ....
    textn.text=rs.fields(comment)