不用RECORDSET,只用CONNECTIONcn.open "provider=sqloledb;server=yourcomputer;database=test;trusted_connection=yes" cn.execute "insert into test ('"& Trim(txtXh.Text) &"', '"& Trim(txtYear.Text))&"')"
注意以下几点: 1、将你的 rs.open "select xh,name from test",cn,adOpenStatic, adLockOptimistic 改为: rs.open "select xh,name from test where id is null",cn,adOpenStatic, adLockOptimistic 'id 是你的自增长字段 2、注意数据类型 如果你的rs.Fields(0)或rs.Fields(1)数据类型为整数的话 要转换在对: rs.Fields(0)=Clng(Trim(txtXh.Text))
cn.execute "insert into test ('"& Trim(txtXh.Text) &"', '"& Trim(txtYear.Text))&"')"
1、将你的
rs.open "select xh,name from test",cn,adOpenStatic, adLockOptimistic
改为:
rs.open "select xh,name from test where id is null",cn,adOpenStatic, adLockOptimistic
'id 是你的自增长字段
2、注意数据类型
如果你的rs.Fields(0)或rs.Fields(1)数据类型为整数的话
要转换在对:
rs.Fields(0)=Clng(Trim(txtXh.Text))