【发布时间】:2011-05-05 18:45:11
【问题描述】:
对 .NET 来说还是个新手,但对我来说这看起来不错。我不知道发生了什么事。我正在尝试将 1 个参数添加到 SqlCommand。它是 SQL Server 中的一个整数,我将一个整数传递给它。
它挂在Command.Parameters.Add(PolicyNo) 代码行上并踢出“由于内部错误而无法处理”。
我也试过了
Command.Parameters.AddWithValue("@PolicyNumber", PolicyNo)
但无济于事。它以相同的错误消息轰炸。代码如下:
Public Function GetPolicyObj(ByVal PolicyNo As Integer) As PolicyInfo Implements ILetterWriter.GetPolicyObj
Dim SQLcon As New SqlClient.SqlConnection
'Establish the connection
SQLcon.ConnectionString = "Data Source=Hosed;Initial Catalog=MyCat;User ID=Goofy;Password=OpenSesame;"
SQLcon.Open()
Using Command As New SqlClient.SqlCommand("sp_GetPolicyInfo", SQLcon)
Command.CommandType = CommandType.StoredProcedure
Command.Parameters.Add(PolicyNo) 'Bombs on this line
Command.Connection.Open()
Dim reader As SqlClient.SqlDataReader = Command.ExecuteReader
有什么想法吗?
谢谢, 杰森
【问题讨论】: