| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1061 人关注过本帖
标题:[求助]请教:如何让employee信息允许Branch_ID为空?
只看楼主 加入收藏
tong__wt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-15
收藏
 问题点数:0 回复次数:6 
[求助]请教:如何让employee信息允许Branch_ID为空?

我的问题比较麻烦,我尽量表述清楚点。

手上代码new.asp和new_exe.asp是实现用户信息(employee)增加的。但是当employee中分公司信息(Branch_ID)为空时,新增用户信息时会报错。报错信息如下:
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/employee/new_exe.asp,行 28

我不知怎么修改这个问题。现将new.asp咯new_exe.asp代码奉上,请高手指教!!

new.asp:
<!--#include file="../config.asp"-->
<!--#include file="../inc/check_login.asp"-->
<!--#include file="../inc/functions.asp"-->
<%
Application_ID = 5000300 '本功能编号,含义请查看编码表
if not CheckAuth(Session("Employee_ID"),Application_ID) then '验证权限
Server.Transfer "../err/un_authorized.htm"
response.end
end if
%>
<!--**************身份验证部分****************-->
<%
Branch_ID = request("Branch_ID")
if Trim(Branch_ID) = "" then Branch_ID = 1
LoginName = request("LoginName")
Password = request("Password")
Employee_Name = request("Employee_Name")
Gender = request("Gender")
Birthday = request("Birthday")
Department_ID = request("Department_ID")
Funcs = request("Funcs")
Tel = request("Tel")
Email = request("Email")
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<form name="frm" action="new_exe.asp" method="post" onSubmit="return CheckInput();">
新员工
<hr size=1>
<table bgcolor="#FFFFFF" border=0 cellpadding=1 cellspacing=1 width="100%">
<tr>
<td bgcolor="#EFEFEF">用户名</td><td><input type="text" name="LoginName" size="20" value="<%= LoginName %>"></td>
<td bgcolor="#EFEFEF">密码</td><td><input type="Password" name="Password" size="20" value="<%= Password %>"></td>
</tr>
<tr>
<td bgcolor="#EFEFEF">姓名</td><td>
<input type="text" name="Employee_Name" size="16" value="<%= Employee_Name %>">
<select name="Gender" size="1">
<% If Gender = 0 then %>
<option value="1">男</option>
<option value="0" SELECTED>女</option>
<% Else %>
<option value="1" SELECTED>男</option>
<option value="0">女</option>
<% End If %>
</select>
</td>
<td bgcolor="#EFEFEF">出生日期</td><td><input type="text" name="Birthday" size="12" value="<%= Birthday %>"></td>
</tr>
<tr>
<td bgcolor="#EFEFEF">分公司、部门</td>
<td>
<select name="Branch_ID" size="1" onChange="return chg_brch(this.value);">
<%
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open connstr
sql = "sp_Employee_Branch"
'response.write sql
set rs = conn.execute(sql)
while not rs.eof
if CStr(Branch_ID) = CStr(rs("Branch_ID")) then
tag = "selected"
else
tag = ""
end if
response.write "<option value=" & rs("Branch_ID") & " " & tag & ">" & rs("Branch_Name") & "</option>"
rs.movenext
wend
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
</select>
<select name="Department_ID" size="1">
<%
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open connstr
sql = "sp_Employee_Department " & Branch_ID
'response.write sql
set rs = conn.execute(sql)
while not rs.eof
Department_ID = rs("Department_ID")
Department_Name = rs("Department_Name")
if trim(Department_Name) = "" then Department_Name = "不属于任何部门"
response.write "<option value=" & Department_ID & ">" & Department_Name & "</option>"
rs.movenext
wend
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
</select>
</td>
<td bgcolor="#EFEFEF">职务</td><td><input type="text" name="Funcs" size="12" value="<%= Funcs %>"></td>
</tr>
<tr>
<td bgcolor="#EFEFEF">电话</td><td><input type="text" name="Tel" size="32" value="<%= Tel %>"></td>
<td bgcolor="#EFEFEF">电子邮件</td><td><input type="text" name="Email" size="32" value="<%= Email %>"></td>
</tr>
</table>
<input type="submit" name="Submit" value="增加新员工">
</form>
</body>
</html>
<script language="JavaScript" type="text/javascript">
function chg_brch(Branch_ID){
var LoginName = document.frm.LoginName.value;
var Password = document.frm.Password.value;
var Employee_Name = document.frm.Employee_Name.value;
var Gender = document.frm.Gender.value;
var Birthday = document.frm.Birthday.value;
var Department_ID = document.frm.Department_ID.value;
var Funcs = document.frm.Funcs.value;
var Tel = document.frm.Tel.value;
var Email = document.frm.Email.value;
var url = 'new.asp?Branch_ID='+Branch_ID+'&LoginName='+LoginName+'&Password='+Password+'&Employee_Name='+Employee_Name+'&Gender='+Gender+'&Birthday='+Birthday+'&Funcs='+Funcs+'&Tel='+Tel+'&Email='+Email;
location.href = url;
}
</script>
<script language="JavaScript" type="text/javascript">
function CheckInput(){
var LoginName = document.frm.LoginName.value;
var Employee_Name = document.frm.Employee_Name.value;
if(LoginName.length < 1){
alert('请正确填写用户名。');
return false;
}else{
if(Employee_Name.length < 1){
alert('请正确填写员工姓名。');
return false;
}else{
return true;
}
}
}
</script>

以上是new.asp代码,功能是增加用户。

new_exe.asp:
<!--#include file="../config.asp"-->
<!--#include file="../inc/check_login.asp"-->
<!--#include file="../inc/functions.asp"-->
<%
Application_ID = 5000300 '本功能编号,含义请查看编码表
if not CheckAuth(Session("Employee_ID"),Application_ID) then '验证权限
Server.Transfer "../err/un_authorized.htm"
response.end
end if
%>
<!--**************身份验证部分****************-->
<%
LoginName = request("LoginName")
Password = request("Password")
Employee_Name = request("Employee_Name")
Gender = request("Gender")
Birthday = request("Birthday")
Branch_ID = request("Branch_ID")
Department_ID = request("Department_ID")
Funcs = request("Funcs")
Tel = request("Tel")
Email = request("Email")

Set conn = Server.CreateObject("ADODB.Connection")
conn.open connstr
sql = "sp_Employee_New '" & LoginName & "','" & Password & "','" & Employee_Name & "'," & Gender & ",'" & Birthday & "'," & Branch_ID & "," & Department_ID & ",'" & Funcs & "','" & Tel & "','" & Email & "'"
'response.write sql
conn.execute(sql)
conn.close
set conn = nothing

'操作日志
Rec_Content = "添加新员工"
Command_Line = sql
call Op_Rec(Rec_Content,Command_Line)
%>
成功添加新员工!
<script language="JavaScript" type="text/javascript">
parent.main.location.reload();
</script>

搜索更多相关主题的帖子: employee Branch 
2007-07-21 11:18
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
这个是数据库的设置问题,Branch_ID在数据库中被设置为不允许为空,可以修改为允许为空。但是如果这个字段是主键的话,最好不要这样修改。
2007-07-21 11:51
tong__wt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-15
收藏
得分:0 

我修改了数据库中employee表里的Branch_ID字段属性为空。但是仍然报错。
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/employee/new_exe.asp,行 28

该怎么办那?

2007-07-21 11:57
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
sql = "sp_Employee_New '" & LoginName & "','" & Password & "','" & Employee_Name & "'," & Gender & ",'" & Birthday & "'," & Branch_ID & "," & Department_ID & ",'" & Funcs & "','" & Tel & "','" & Email & "'"
这个sp_Employee_New是楼主在数据库中写的一个存储过程?
也可以做一个判断来处理
比如
在这句话之前加一句
Set conn = Server.CreateObject("ADODB.Connection")
conn.open connstr
IF Branch_ID="" Then Branch_ID="0"
sql = "sp_Employee_New '" & LoginName & "','" & Password & "','" & Employee_Name & "'," & Gender & ",'" & Birthday & "'," & Branch_ID & "," & Department_ID & ",'" & Funcs & "','" & Tel & "','" & Email & "'"
'response.write sql
conn.execute(sql)
conn.close
加一个判断防止为空。
set conn = nothing
2007-07-21 12:07
tong__wt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-15
收藏
得分:0 
回复:(yms123)sql =

很感谢楼上的跟踪!!
我将sp_Employee_New这个存储过程发上来请看看。

/*
** 删除消息
*/
CREATE procedure sp_Employee_New
@LoginName varchar(20),
@Password varchar(20),
@Employee_Name nvarchar(32),
@Gender bit,
@Birthday datetime,
@Branch_ID int,
@Department_ID int,
@Funcs nvarchar(32),
@Tel varchar(32),
@Email varchar(50)
as
insert into Employee(LoginName,[Password],Employee_Name,Gender,Birthday,Branch_ID,Department_ID,Funcs,Tel,Email)
values(@LoginName,@Password,@Employee_Name,@Gender,@Birthday,@Branch_ID,@Department_ID,@Funcs,@Tel,@Email)


GO
我试过楼上的代码。仍然出现
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/employee/new_exe.asp,行 31
麻烦再给点建议

2007-07-21 12:16
tong__wt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-15
收藏
得分:0 
大家帮忙啊!!
2007-07-21 17:36
tong__wt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-15
收藏
得分:0 
???
2007-07-23 09:16
快速回复:[求助]请教:如何让employee信息允许Branch_ID为空?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013666 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved