ASP.NET processing data error

xiaoxiao2021-03-06  186

@ERRORCreate PROCEDURE InsertEmployee (@FirstName nvarchar (10)) AS INSERT INTO Employees (firstname) VALUES (@FirstName) RETURN @@ ERRORDim cmd As New SqlCommand (sql, conn) cmd.CommandType = CommandTyle.StoredProcedure // SQLSERVER stored procedure cmd .Parameters.add ("@ firstname", "mark") Try cmd.executenonquery () Catch exception response.write ("Error:" & ex.Message &) End Try

Use the raiserror command to trigger database error raiserror ({msg_id | msg_str} {, severity, state} [, argument [, ... n]])

MSG_ID If you want to use the message stored in the sysmessage table, specify this value in the "ERROR" field. Note that you can only use the number of messages Msg_STR numbered in more than 13000 to represent the error text. If this parameter is specified instead of MSG_ID, the MSG_ID default value is 50000. Any number of error messages numbered 50,000 or more than 5,000,000 is considered to be a relative severity of the user-defined Severity this value. You can specify a value between 0-18 (18 represents the most severe); the value outside the range is saved by SQL. In some places, we also call any numbers between "Level" State 1-127, used to indicate the status of this error when the error occurs.

IF @error <> 0 Begin Raiserror ('Error Log Couldn't Be Updated ", 1, 1) Endend

Handling Error in .NET System.Data.sqlexception member class Class The first error generated during the SQL statement execution period contains an instance of the SQLEOOROCOLECTION class of the SQLEOorocollection class. SQL can return multiple errors, you can use this collection to enumerate these errors. The wrong text content generated by Message. If multiple errors are generated, all text will be added and the Enter is separated from them. Number The first error message ID generated in the ERRORS collection. If you point out an error via the SQL statement, Number is default the first error of the 5000State in the ErrorS collection.

Try cmd.executenonquery () catch ex as system.data.sqlclient.sqlexception response.write (Replace (Ex.Message, ControlChars.lf, ")))))) DIM SERR AS SQLERROR for Each Serr in Ex. Errors Response.write (Replace (Ex.Message, ControlChars.LF, "))) NEXTEND TRY

转载请注明原文地址:https://www.9cbs.com/read-128863.html

New Post(0)