<!--#include file = "adovbs.inc" -->
<%'取得用户输入信息，并删除首尾空格
no=Trim(Request.Form("no"))
name=Trim(Request.Form("name"))
'如果用户输入的信息有一项为空，重定向到输入页面
If no="" or name=""  then 
   Response.Redirect "department.htm"
End If
'打开数据库，建立连接
Set conn = Server.CreateObject("ADODB.Connection")
strProvider="Provider=SQLOLEDB.1;Data Source=localhost;Initial Catalog=person ; User ID=sa; Password=123; "
conn.Open strProvider
'检查用户输入的数据是否已经存在 
Commandtext = "Select * From t_department where number='" & no & "'"
set rs=conn.Execute(commandtext,,adcmdtext)
If rs.eof then
   '如果不存在相应记录，则向表添加数据
   Commandtext= "Insert into t_department(number,d_name) VALUES('" & no & "','" & name & "')"
   conn.Execute commandtext,,adcmdtext
   Response.Write "数据添加成功！<BR>"
Else
   '如果存在相应记录，则修改记录数据
   Commandtext="Update t_department Set d_name='" & name & "' Where number='" &no & "'"
   conn.Execute commandtext,,adcmdtext
   Response.Write "数据修改成功！<BR>"
End If
Set conn = nothing  %>
