送分100分:再问ISNULL使用。
有如下一个语句:
sql = "INSERT INTO 表1(用户编号,用户姓名,工资)" + " values (" & RST.fields("编号") & "," + RST.Fields("姓名") +"," & Gongzi &" )"
用户编号和工资两字段为数值,用户姓名为文本,均为非必填字段。
问题如下:
1、当用户编号、工资、用户姓名分别为空白字段时,应如何构造此SQL语句才能保证此SQL语句的正常执行。
[解决办法]
isnull(用户编号,' ') as 用户编号
[解决办法]
function SQLString(byval v as variant) as string if IsNull(v) Then SQLString = "NULL" else SQLString = "'" & v & "'" end ifend ifsql = "INSERT INTO 表1(用户编号,用户姓名,工资) values (" & _ SQLString(RST.fields("编号").Value) & "," & _ SQLString(RST.Fields("姓名").Value) & "," & _ SQLString(Gongzi) & " )"
[解决办法]
sql=" insert into 表1(用户编号,用户姓名,工资) values("& iif(isnull(rst!编号)=true,"NULL","" & rst!编号 &"") &","& iif(isnull(rst!姓名)=true,"NULL","'"& rst!姓名 &"'") &","& iif(isnull(rst!工资)=true,"NULL",""& rst!工资 &"") &")"
[解决办法]