2016-08-04 116 views
0

我有以下存储过程:VB.NET过程或函数的参数太多指定

CREATE PROCEDURE MyProc  
@posted_xml_body xml  
AS  
INSERT INTO MyTable  
(post_datetime, post_body)  
VALUES  
(getdate(), @posted_xml_body) 

而下面的VB代码:

Using aConnection As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings(connectionString).ConnectionString) 
    aConnection.Open() 
    Dim aCommand As New Data.SqlClient.SqlCommand("MyProc", aConnection)  
    aCommand.CommandType = Data.CommandType.StoredProcedure 
    aCommand.Parameters.AddWithValue("@posted_xml_body", aXMLString) 

    Dim rows_affected As Integer = aCommand.ExecuteNonQuery() 

    aCommand.Dispose() 
    aConnection.Close() 

    Return rows_affected 

End Using 

不过,我不断收到以下错误

“过程或函数指定的参数太多。”

感谢您的任何建议。

+0

哪里是在存储过程的最后括号(后GETDATE(),XML_Body)? –

+0

对不起,我忘了将它包含在我的问题中,但它在那里。值 (getdate(),@posted_xml_body) – mike

+0

这里我利用.ExecuteScalar获得返回值....我看不到任何其他问题在你的程序。 –

回答

0

您粘贴错误或缺少 “)” 在这里

VALUES  
(getdate(), @posted_xml_body) 
0

有几件事情我会建议。

将列类型改为nvarchar(max),选择范围标识,只需确保您的表为主键,因为您的VB代码会给您一个尝试将日期转换为整数的异常。

CREATE PROCEDURE MyProc  
@posted_xml_body as nvarchar(max)  
AS 
Begin 
INSERT INTO MyTable  
(post_datetime, post_body)  
VALUES  
(getdate(), @posted_xml_body);SELECT SCOPE_IDENTITY() 
END 

你VB代码

Using aConnection As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings(connectionString).ConnectionString) 

    Dim rows_affected As Integer = 0 

    Try 
     aConnection.Open() 

     Dim aCommand As New Data.SqlClient.SqlCommand("MyProc", aConnection) 

     aCommand.CommandType = Data.CommandType.StoredProcedure 
     aCommand.Parameters.AddWithValue("@posted_xml_body", aXMLString) 
     rows_affected = aCommand.ExecuteScalar() 
    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    Finally 
     If aConnection.State = ConnectionState.Open Then 
      aConnection.Close() 
     End If 
    End Try 

    Return rows_affected 

End Using 
相关问题