我正在尝试使用存储过程在 SQL Server 2008 R2 表中插入一条记录。我正在“尝试”编写一个用于数据库访问的通用类。
这是 .VB 文件中的代码:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If PreviousPage IsNot Nothing AndAlso PreviousPage.IsCrossPagePostBack Then
Dim params(5) As SqlParameter
params(0) = New SqlParameter("@Name", PreviousPage.Name.Text)
params(1) = New SqlParameter("@Qualification", PreviousPage.Qualification.Text)
params(2) = New SqlParameter("@ContactNo", PreviousPage.ContactNo.Text)
params(3) = New SqlParameter("@Expertise", PreviousPage.Expertise.Text)
params(4) = New SqlParameter("@Comments", PreviousPage.Comments.Text)
params(5) = New SqlParameter("@Affiliation", PreviousPage.Affiliation.Text)
DAL.DoInsertSP(params)
End If
End Sub
这是 DAL.DoInsertSP() 的代码:
Public Shared Function DoInsertSP(ByRef params As Array) As Byte
Dim result As Byte = 0
CreateConnection()
cmd = New SqlCommand("sp_InsertExpert", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddRange(params)
Try
result = CByte(cmd.ExecuteNonQuery())
Catch ex As Exception
conn.Dispose()
End Try
Return result
End Function
代码抛出System.OverflowException:算术运算导致溢出。
这是 proc sp_InsertExpert的脚本
USE [dbherpes]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_InsertExpert]
@Name nvarchar(30) = null,
@Qualification nvarchar(40) = null,
@ContactNo nvarchar(13) = null,
@Expertise nvarchar(30 ) = null,
@Comments nvarchar(100) = null,
@Affiliation nvarchar(50) = null AS
BEGIN
SET NOCOUNT ON;
插入专家(姓名、资格、联系人编号、专业知识、评论、附属机构)值(@Name、@Qualification、@ContactNo、@Expertise、@Comments、@Affiliation)
结束
这是表的结构:
请问我该如何纠正?
更新
我已设置 ID 列的身份规范 = '是',身份增量 = 1,身份种子 = 1