直播中
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'判斷錯誤的個數(shù)
IsSucc = " 成功 "'
Else
select case Conn.Errors.Item(0).NativeError
case 2627
IsSucc = "ddddddd" '你可以根據(jù)需要,定義多個自己的錯誤返回值
End Select
End if
Response.Write "<br>:::"&IsSucc
%>
注意select case…一句中的“Conn.Errors.Item(0).NativeError”,返回一組item中的第一個。在我們這個例子當中,伴隨2627措促同時發(fā)生的是“語句已終止”(3621),嚴格來講,他不是錯誤,而是一般性警告(嚴重級別=10)。所以我們需要用來判斷的是第一個錯誤,當然,你可以定義i = i + 1來查看所有發(fā)生的錯誤。這樣,我們就能夠知道來自SQL Server的錯誤的具體內(nèi)容,可以更容易的控制了。
附:錯誤編號
<!—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">總計數(shù):<%=RS.RecordCount%></td>
<TD width="80">總頁數(shù):<%=RS.PageCount%></TD>
<TD width="90">目前頁次:<%=page%></TD>
<TD width="80">轉(zhuǎn)到<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-->
另:有關(guān)ADO2.1與Conn.Errors的說明,請見ms-help://MS.MSDNVS.2052/dnaxctrl/html/ado_objm.htm