注册 登录
编程论坛 ASP技术论坛

[求助]应该是数据库问题(菜鸟问题)

xiaoxippzyh 发布于 2007-08-10 00:34, 439 次点击

出现一个问题,能帮我解决一下么?这个是数据库的设置问题,还是代码写错了
Microsoft OLE DB Provider for SQL Server (0x80040E2F)
无法将 NULL 值插入列 'u_id',表 'text4.dbo.user';该列不允许空值。INSERT 失败。
/xiaoxippzyh/text4/add_save.asp, 第 25 行

代码是<!--#include file="include/config.asp"-->
<!--#include file="include/conn.asp"-->

<% dim str
str=""
if request("name")="" then
str=str & "请输入姓名 <br>" '不加response.write怎么输出丫?

end if
if not isnumeric(request("age")) then
str=str &"请填写年龄 <br>"
end if
dim strsql,thisdate
thisdate=request("year")&"-"&request("month")&"-"&request("day")
dim rs
StrSql="select * from [user] order by u_id desc"
set rs=Server.CreateObject("ADODB.RecordSet")
rs.open StrSql,conn,3,3
rs.addnew
rs("u_name")=trim(request("name"))
rs("u_sex")=trim(request("sex"))
rs("u_age")=trim(request("age"))
rs("u_date")=thisdate
rs("u_jianjie")=trim(request("jianjie"))
rs.update
str="保存成功"
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<table width="332" height="82" border="1" align="center">
<tr>
<td bgcolor="#FFFFE6"><%=str%></td>
</tr>
</table>
</body>
</html>
<!--#include file="include/connclose.asp"-->




有人说这是数据库设置问题
字段你设置的不能为空 而你插入的时候该字段是空值
把字段设置为可以为空 或者在页面作不能为空的验证
具体在数据库里怎么操作?
id为主键肯定不能为空的,其他的都可以丫,

2 回复
#2
ouyangfeixue2007-08-10 08:44
把这个 rs.open StrSql,conn,3,3换成 rs.open StrSql,conn,1,3,还有,你用的是什么数据库.如果是SQL SERVER是可以插入的.前提是这个字段可以为空.如果是ACCESS的,你想插入的话,就要这样:insert into table values('NULL')不明白的地方请联系我,QQ:308046190.我的QQ群:31758718
#3
xiaoxippzyh2007-08-14 23:55

谢谢,
我搞定了

1