access自动编号问题
我用access数据库
设置了几个字段,也有id(自动编号)
用了insert语句后出现错误:
错误类型:
Microsoft JET Database Engine (0x80040E14)
INSERT INTO 语句的语法错误。
只要我把id(自动编号)去掉
数据就写入了数据库
不去掉id(自动编号)
就是上述错误
高手帮忙啊!看看哪里错了!
代码如下:
<%
dim conn,rs
set conn=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
conn.connectionstring="provider=Microsoft.Jet.oledb.4.0;data source="& server.mappath("ceshi.mdb")
conn.open
set rs=conn.execute("select * from fabu where user='"& user &"' and lanmu='"& lanmu &"' and leibie='"& leibie &"' and jiage='"& jiage &"' and biaoti='"& biaoti &"' and tel='"& tel &"' and email='"& email &"' and miaoshu='"& miaoshu &"'")
if rs.eof then
conn.execute("insert into fabu(username,pwd,user,lanmu,leibie,jiage,biaoti,tel,email,miaoshu,time) values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
response.write"<font color='#ffffff'>恭喜您!您发布的信息已经提交成功!</font>"
else
response.write"<font color='#ffffff'>此条信息您已经发布过了,如果想继续发布,请返回继续发布!</font>"
end if
%>
问题点数:30、回复次数:12Top
1 楼cabell0806(口米口)回复于 2006-03-14 16:06:47 得分 0
有两种情况:
1.数据库里没有id(自动编号)这个字段
insert语句为:
conn.execute("insert into fabu values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
正确
insert语句为:
conn.execute("insert into fabu(username,pwd,user,lanmu,leibie,jiage,biaoti,tel,email,miaoshu,time) values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
错误
2.数据库里有id(自动编号)
上面第一条语句显示错误:查询和插入字段数不一致
上面第二条语句显示错误:insert语句语法错误
郁闷啊
高手们帮忙啊!
Top
2 楼Cooly(☆不做开发很久了......☆)回复于 2006-03-14 16:18:24 得分 0
自动编号不可修改,所以应该在insert into的时候指定字段名
insert into table (field1,field2....) values(value1,value2.....)Top
3 楼Cooly(☆不做开发很久了......☆)回复于 2006-03-14 16:22:25 得分 15
conn.execute("insert into fabu (username,pwd,[user],lanmu,leibie,jiage,biaoti,tel,email,miaoshu,[time]) values('" & username & "','" & pwd & "','" & user & "','" & lanmu & "','" & leibie & "','" & jiage & "','" & biaoti & "','" & tel & "','" & email & "','" & miaoshu & "','" & time & "')")
Top
4 楼niehuihui(在逆境中求发展)回复于 2006-03-14 16:23:01 得分 0
同意楼上的
自动编号不可修改,所以应该在insert into的时候指定字段名
insert into table (field1,field2....) values(value1,value2.....)
Top
5 楼cabell0806(口米口)回复于 2006-03-14 16:45:49 得分 0
我试过了
自动编号应该是自己插入数据库的吧
conn.execute("insert into fabu(username,pwd,user,lanmu,leibie,jiage,biaoti,tel,email,miaoshu,time) values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
这是我写的,都指定了字段名
可是就出错
说语法错误啊!Top
6 楼cabell0806(口米口)回复于 2006-03-14 16:49:32 得分 0
在user和time那加 [] 做什么?
是因为那个错误吗?
我把自动编号去掉后,用
conn.execute("insert into fabu values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
就是正确的,用
conn.execute("insert into fabu(username,pwd,user,lanmu,leibie,jiage,biaoti,tel,email,miaoshu,time) values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
就是错误的
加上自动编号 第二条也还是错误的Top
7 楼Hellohuan(java 好不好???)回复于 2006-03-14 17:10:18 得分 0
既然是自动编号怎么可以指定值呢?Top
8 楼LifeForCode(用生命编程.再入轮回(2007))回复于 2006-03-14 17:36:08 得分 15
[]表明是字段而不是sql语句的关键字
自动编号的值不能修改和指定的,你直接用access打开数据库手动修改下就知道怎么回事了
Top
9 楼yutian130(骑着布什好歹的萨达姆猪,漫步在小巷的尽头)回复于 2006-03-14 18:25:42 得分 0
cabell0806(口米口) ( ) 信誉:100 2006-03-14 16:49:00 得分: 0
在user和time那加 [] 做什么?
是因为那个错误吗?
我把自动编号去掉后,用
conn.execute("insert into fabu values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
就是正确的,用
conn.execute("insert into fabu(username,pwd,user,lanmu,leibie,jiage,biaoti,tel,email,miaoshu,time) values('"+ username +"','"+ pwd +"','"& user &"','"& lanmu &"','"& leibie &"','"& jiage &"','"& biaoti &"','"& tel &"','"& email &"','"& miaoshu &"','"& time &"')")
就是错误的
加上自动编号 第二条也还是错误的
//是不是选择了必填字段??Top
10 楼qingqingnet(青青)回复于 2006-03-14 21:43:18 得分 0
换另外一种插入方式Top
11 楼cabell0806(口米口)回复于 2006-03-14 22:14:53 得分 0
哈哈
搞定了
多谢了
有事
一会儿来结贴给分了!Top
12 楼cabell0806(口米口)回复于 2006-03-14 22:40:02 得分 0
我回来了
谢谢各位热心的帮助我
不吝赐教
结贴了!Top




