update table1 set f=" & iif(Check1.Value=1,"true","false")
dim tmp_value as boolean if check1.value=1 then tmp_value=true else tmp_value=false end if cn.execute " update tablename set 字段="& tmp_value &""
rappercn(rapper) ,写的很好。
update table1 set f=" & iif(Check1.Value=1,true,false)
update table1 set f='" & iif(Check1.Value=1,"true","false")'
update table1 set f='" & iif(Check1.Value=1,"true","false")&"'
SQL语句:"update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")因为字段是布尔型,所以在等于号后不需要加引号。
风之兄: "update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")这样正确吗?UPDATE前面有个 " 但语句最后没有啊?
另一个在等于号后面。 iif(Check1.Value=1,"true","false") 的意思是根据Check1的Value值来生一个值为"True"或"False" 的字符串。 所以将这两段加起来就是你需要的SQL语句了。如果你的是ADO,则: Dim Conn As ADODB.Connection Conn.open "你的连接字符串" Conn.Execute "update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")如果是DAO,则: Dim Db As Database Set Db=DbEngine.Opendatabase(.....) Db.Execute "update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")
风之兄的也许后面还得加引号(没有测试过啊,报歉!) SQL语句:"update 表名 set 字段名=" + iif(Check1.Value=1,"true","false") & chr$(34)
"update table1 set f=" & iif(Check1.Value=1,1,0)
"update 表名 set 字段名='" + iif(Check1.Value=1,1,0)+"'"
下面是我的测试代码,VB6 + Win98 下通过。Private Sub Command1_Click() '用ADO Dim Conn As New ADODB.ConnectionConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\ctnexport\data\back\export.mdb;Persist Security Info=False" Conn.Execute "update data set reload=" + IIf(Check1.Value = 1, "true", "false")Conn.Close End SubPrivate Sub Command2_Click() '用DAO Dim Db As DatabaseSet Db = DBEngine.OpenDatabase("D:\ctnexport\data\back\export.mdb")Db.Execute "update data set reload=" + IIf(Check1.Value = 1, "true", "false")Db.Close End Sub
风兄,那对啊,我是用ADO,不过操作系统是XP,ACCESS也是XP的,是不 是这儿有问题呢?
我同意 qbilbo(风之兄) 因为他写的这个绝对没有问题~~~至于XP我想你用什么做连接的 ?Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents and Settings\wd1\My Documents\db1.mdb;Persist Security Info=FalseProvider=Microsoft.Jet.OLEDB.4.0;是关键,你是不是用的3.51啊?用4.0应该没有问题的~~
rs,open sqlstr,cn,3,3
if check1.value=1 then
tmp_value=true
else
tmp_value=false
end if
cn.execute " update tablename set 字段="& tmp_value &""
iif(Check1.Value=1,"true","false") 的意思是根据Check1的Value值来生一个值为"True"或"False" 的字符串。
所以将这两段加起来就是你需要的SQL语句了。如果你的是ADO,则:
Dim Conn As ADODB.Connection
Conn.open "你的连接字符串"
Conn.Execute "update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")如果是DAO,则:
Dim Db As Database
Set Db=DbEngine.Opendatabase(.....)
Db.Execute "update 表名 set 字段名=" + iif(Check1.Value=1,"true","false")
SQL语句:"update 表名 set 字段名=" + iif(Check1.Value=1,"true","false") & chr$(34)
应该没有错吧ConnMDB.Execute "update ksotherinfo set DELETE=" + IIf(Check1.Value = 1, "true", "false")
Dim Conn As New ADODB.ConnectionConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\ctnexport\data\back\export.mdb;Persist Security Info=False"
Conn.Execute "update data set reload=" + IIf(Check1.Value = 1, "true", "false")Conn.Close
End SubPrivate Sub Command2_Click() '用DAO
Dim Db As DatabaseSet Db = DBEngine.OpenDatabase("D:\ctnexport\data\back\export.mdb")Db.Execute "update data set reload=" + IIf(Check1.Value = 1, "true", "false")Db.Close
End Sub
ConnMDB.Execute "update ksotherinfo set [DELETE]=" + IIf(Check1.Value = 1, "true", "false")
最终于有人搞正确了,我用的那个字段正好是SQL语句的保留字DELETE,呵呵
这个人就是 awfikthh(百无聊赖)
不过风之兄提供了方法,太好了
结帐我的信仰:有问题,在CSDN上请教!!!!!!!!!!!!!