none
How do I find the source of my insertcommand error RRS feed

  • Question

  • Hi;

    I am using the insert command to create a new record via a SPROC in SQL2008.

     

     

    Dim InsertCommand As New SqlCommand("Special_insert", conn)

    InsertCommand.CommandType =

     

    CommandType.StoredProcedure

    InsertCommand.Parameters.AddWithValue(

     

    "@Acct_Nbr", MyRec.Acct_Nbr_Addvg)

    InsertCommand.Parameters.AddWithValue(

     

    "@Last_Name", MyRec.Last_Name)

    InsertCommand.Parameters.AddWithValue(

     

    "@StreetAddress", MyRec.StreetAddress)

    InsertCommand.Parameters.AddWithValue(

     

    "@city", MyRec.City)

    InsertCommand.Parameters.AddWithValue(

     

    "@state", MyRec.State)

    InsertCommand.Parameters.AddWithValue(

     

    "@zip", MyRec.Zip)

     

     

    Try

    conn.Open()

    InsertCommand.ExecuteNonQuery()

     

     

    Catch ex As SqlException

     

     

    MyErrorLog.Log("Error", ex)

     

     

    ' Throw ex

     

     

    Finally

    conn.Close()

     

     

    End Try

    MyRec is my business object.

    I keep getting an error message stating that @Last_Name wasn't supplied.

    Please see error message"

    System.Data.SqlClient.SqlException (0x80131904): Procedure or function '_insert' expects parameter '@Last_Name', which was not supplied.

    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)

    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

    at MyDE.InsertData(ARecord myRec).

    I tried getting rid of the @ thinking since my data type are defined in my business object this wasn't necessary. Wrong.

    I am really at a loss here.

    Thanks for any insights !

    Friday, January 14, 2011 8:27 PM

Answers

All replies