2016-08-04 1 views
0

je la procédure stockée suivante:VB.NET procédure ou de fonction a trop d'arguments spécifiés

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

Et le code VB suivant:

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 

Cependant, je continue à recevoir l'erreur suivante

"La procédure ou la fonction a trop d'arguments spécifiés."

Merci pour vos suggestions.

+0

Où est la parenthèse finale procédure stockée (après GetDate(), XML_Body)? –

+0

Désolé, j'ai oublié de l'inclure dans ma question mais c'est là. VALEURS (getdate(), @posted_xml_body) – mike

+0

Ici j'utilise .ExecuteScalar pour obtenir une valeur de retour .... Je ne vois pas d'autre problème dans votre procédure. –

Répondre

0

vous avez collé mal ou il manque un ")" ici

VALUES  
(getdate(), @posted_xml_body) 
0

Il y a des choses ou deux je suggère. Modifiez le type de colonne en nvarchar (max), sélectionnez l'identité de la portée, assurez-vous simplement que votre table est une clé primaire car le code vb vous donnera une exception en essayant de convertir la date en nombre entier.

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 

Votre Code 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