又是数据库连接的问题
<html>
<BODY bgcolor= "#ccffcc ">
<H2 align =center> 学 生 基 本 数 据 录 入 </H2>
<HR>
<Form method=POST name=add action= "d_ins.asp ">
<DIV align=center>
<TABLE border=0>
<TR>
<TD height= "41 "> 姓名: </TD>
<TD> <input type= "text " name= "name " size= "20 "> </TD>
</TR>
<TR>
<TD height= "35 "> 学号: </TD>
<TD> <input type= "text " name= "number " size= "20 "> </TD>
</TR>
<TR>
<TD height= "36 "> 班级: </TD>
<TD> <INPUT type= "text " name= "class " size= "20 "> </TD>
</TR>
<TR>
<TD height= "34 "> 性别: </TD>
<TD> <SELECT size= "1 " name= "sex ">
<OPTION selected value= "男 "> 男 </OPTION>
<OPTION valuve= "女 "> 女 </OPTION>
</SELECT> </TD>
</TR>
<TR>
<TD height= "33 "> 民族: </TD>
<TD> <INPUT type= "text " name= "minzu " size= "20 "> </TD>
</TR>
<TR>
<TD height= "39 "> 籍贯: </TD>
<TD> <input type= "text " name= "jiguan " size= "20 "> </TD>
</TR>
<TR>
<TD height= "37 "> 联系电话: </TD>
<TD> <INPUT type= "text " name= "phone " size= "20 "> </TD>
</TR>
</TABLE>
<INPUT type=submit value= "确定 " name=B1>
<INPUT type=reSet value= "重填 " name=B2>
</DIV>
</Form>
</BODY>
</HTML>
d_ins.asp的代码是下面:
<%
on error resume Next
'取得用户输入的数据
t_name=request.form( "name ")
t_number=request.form( "number ")
t_class=request.form( "class ")
t_sex=request.form( "sex ")
t_minzu=request.form( "minzu ")
t_phone=request.form( "phone ")
t_jiguan=request.form( "jiguan ")
'创建数据库的连接
Set conn = Server.CreateObject( "ADODB.Connection ")
strProvider = "Provider=sqloledb;Data Source=(local);Initial Catalog=tx1;User ID=sa; Password=; "
conn.Open strProvider
'添加时使用的字段
fields=array( "t_name ", "t_number ", "t_class ", "t_sex ", "t_mizu ", "t_phone ", "t_jiguan ")
values=array(t_name,t_number,t_class,t_sex,t_minzu,t_phone,t_jiguan)
sql = "INSERT INTO t_student( " & Join(fields, ", ")& ") VALUES ( ' "&_
Join(values, " ', ' ")& " ') "
'添加数据
conn.Execute sql
'判断执行是否成功
If conn.Errors.Count> 0 Then
Response.Write "系统发生 "&conn.errors.Count& "个错误! "
Else
Response.Write "数据添加成功! "
End If
Set conn=nothing
%>
我调试时,提示有一个错误,不知道是什么错误,高手们指点下,或者大家有连接SQL SERVER 2000 可以进行数据添加的代码可以发上来.
谢谢!
[解决办法]
'on error resume Next注释这句不就知道是什么错误了?
[解决办法]
strProvider = "Provider=sqloledb;Data Source=(local);Initial Catalog=tx1;User ID=sa; Password=; "
改成这样试试:
strProvider = "Provider=sqloledb;Data Source=(local);Initial Catalog=tx1;Uid=sa; Pwd=; "
[解决办法]
所有的字段都是字符型的吗?
[解决办法]
<%
set rst=server.CreateObject( "adodb.recordset ")
on error resume next
id=request.querystring( "id ")
if request.querystring( "act ")= "modify " then
conn.begintrans
rst.open "select * from dv_user where userid= " & id,conn,1,3
rst( "sdoom_qq ")=request.form( "sdoom_qq ")
rst( "sdoom_is ")=request.form( "sdoom_is ")
rst( "sdoom_jru ")=request.form( "sdoom_jru ")
rst( "sdoom_old ")=request.form( "sdoom_old ")
rst.update
rst.close
if err.number <> 0 then
conn.rollbacktrans
response.write " <script language=javascript> alert( '请认真添写您的个人资料~! ') </script> "
else
conn.committrans
response.write " <script language=javascript> alert( '恭喜您~!您的申请已经递交成功~!请等待审核~! ');window.open( 'index.asp ', '_parent '); </script> "
end if
%>