Conn.Open"DSN=BBII; UID=sa; PWD="
SQL="Exec ch_insNovel 'd','22','33','44','55'"
'SQL = "Insert Into Novel (Name,Author,yy,ee)VALUES('nn','ee','jj')",与上句效果是一样的
RS.Open SQL,Conn
If Conn.Errors.Count = 0 Then'判断错误的个数
IsSucc = " 成功 "'
Else
select case Conn.Errors.Item(0).NativeError
case 2627
IsSucc = "ddddddd" '你可以根据需要,定义多个自己的错误返回值
End Select
End if
Response.Write "<br>:::"&IsSucc
%>
注意select case…一句中的“Conn.Errors.Item(0).NativeError”,返回一组item中的第一个。在我们这个例子当中,伴随2627措促同时发生的是“语句已终止”(3621),严格来讲,他不是错误,而是一般性警告(严重级别=10)。所以我们需要用来判断的是第一个错误,当然,你可以定义i = i + 1来查看所有发生的错误。这样,我们就能够知道来自SQL Server的错误的具体内容,可以更容易的控制了。
附:错误编号
<!—ErrLp.asp-->
<%ON ERROR RESUME NEXT
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Driver={SQL Server}; Server=127.0.0.1; database=master; UID=sa; pwd="
set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "Select * From sysmessages Where msglangid = 2052 Order By error"
rs.open sql,conn,3,2
PAGE = CLng(REQUEST("txtpage"))
RS.PageSize = 100
If PAGE < 1 Then PAGE = 1
If PAGE > RS.PageCount Then PAGE = RS.PageCount
RS.AbsolutePage = PAGE
%>
<style>
td
{
font-family: Verdana;
font-size: 10pt;
}
</style>
<Div>
<FORM METHOD="GET">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#999999">
<TR>
<TD width="100">总计数:<%=RS.RecordCount%></td>
<TD width="80">总页数:<%=RS.PageCount%></TD>
<TD width="90">目前页次:<%=page%></TD>
<TD width="80">转到<INPUT TYPE="text" NAME="txtpage" SIZE="2" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">页</TD>
<TD width="60">
<%
If page <> 1 Then
Response.Write"<a href=ErrorLp.asp?txtpage=1>第一页</a>"%> </TD>
<TD width="60">
<%Response.Write"<a href=ErrorLp.asp?txtpage="&(page - 1)&">上一页</a>"%> </TD>
<%
End If
If page <>RS.PageCount Then%>
<TD width="60">
<%Response.Write"<a href=ErrorLp.asp?txtpage="&(page + 1)&">下一页</a>"%> </TD>
<TD width="70"><%Response.Write"<a href=ErrorLp.asp?txtpage="&RS.PageCount&">最后一页</a>"
End If
%>
</TD>
<TD> </TD>
</TR>
</TABLE>
</FORM>
</DIV>
<p>
<DIV>
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="1" WIDTH="100%" bordercolor="#999999">
<TR>
<TD>错误号</TD>
<TD>严重级别</TD>
<TD>DLEVEL</TD>
<TD>信息</TD>
</TR>
<%For ipage = 1 To RS.PageSize%>
<TR onmouseOver="javascript:this.style.background='#dddddd';" onmouseOut="javascript:this.style.background='';">
<TD><%=RS("error")%></TD>
<TD><%=RS("severity")%></TD>
<TD><%=RS("dlevel")%></TD>
<TD><%=RS("description")%></TD>
</TR>
<% RS.MoveNext
IF RS.EOF THEN EXIT FOR
NEXT
SET RS = NOTHING
SET Conn = NOTHING
%>
</TABLE>
</DIV>
<!--CorpRight By Cheery_Ke-->
另:有关ADO2.1与Conn.Errors的说明,请见ms-help://MS.MSDNVS.2052/dnaxctrl/html/ado_objm.htm
……