²¶»ñSqlÒì³£
°ïÖúÀïµÄ,Óï·¨:
BEGIN TRY
{ sql_statement | statement_block }
END TRY
BEGIN CATCH
[ { sql_statement | statement_block } ]
END CATCH
[ ; ]
Òì³£²¿·Ö:
ÔÚ CATCH ¿éµÄ×÷ÓÃÓòÄÚ£¬¿ÉÒÔʹÓÃÒÔÏÂϵͳº¯ÊýÀ´»ñÈ¡µ¼Ö CATCH ¿éÖ´ÐеĴíÎóÏûÏ¢£º
ERROR_NUMBER() ·µ»Ø´íÎóºÅ¡£
ERROR_SEVERITY() ·µ»ØÑÏÖØÐÔ¡£
ERROR_STATE() ·µ»Ø´íÎó״̬ºÅ¡£
ERROR_PROCEDURE() ·µ»Ø³öÏÖ´íÎóµÄ´æ´¢¹ý³Ì»ò´¥·¢Æ÷µÄÃû³Æ¡£
ERROR_LINE() ·µ»Øµ¼Ö´íÎóµÄÀý³ÌÖеÄÐкš£
ERROR_MESSAGE() ·µ»Ø´íÎóÏûÏ¢µÄÍêÕûÎı¾¡£ ¸ÃÎı¾¿É°üÀ¨ÈκοÉÌæ»»²ÎÊýËùÌṩµÄÖµ£¬È糤¶È¡¢¶ÔÏóÃû»òʱ¼ä¡£
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
¸üÐÂÏÂÎÊÌ⣺
񡜧TBL_Info
×ֶΣº
infoId int
title varchar(20)
Content text
byUser varchar(20)
createTime datetime
1¡¢ÈçºÎɾ³ý±íÖÐÊý¾ÝÏàͬµÄÊý¾ÝÄØ£¿£¨Ö÷¼ü³ýÍ⣩
2¡¢ÈçºÎɾ³ýÊý¾Ý±íÖÐij¸ö×Ö¶ÎÊý¾ÝÏàÍ ......
using System.Data; // Use ADO.NET namespace
using System.Data.SqlClient;
SqlConnection thisConnection = new SqlConnection(
&nbs ......