locked
Can you use a parameter of type of object ? RRS feed

  • Question

  • User-49466106 posted

    Hi;

    Can you declare all of the parms in a class this way ?

     

    <asp:ObjectDataSource ID="ObjectDataSource1"  DataObjectTypeName="StateRecord" Selectmethod="GetStatesByPage" UpdateMethod="UpdateStatesData" InsertMethod="InsertStatesData" TypeName="TrustStatesDE"
       OldValuesParameterFormatString="{0}" runat="server" EnablePaging="true" StartRowIndexParameterName="startIndex" SelectCountMethod="SelectCount" MaximumRowsParameterName="maxRows" >
       <InsertParameters>
          <asp:Parameter Name="StateRecord" Type="Object" />
       </InsertParameters>
       <UpdateParameters>
         <asp:Parameter Name="StateRecord" Type="Object" />
       </UpdateParameters>
       </asp:ObjectDataSource>
     
    I keep getting an error when I try to insert a record stating that my inserrt command can't find a parameter.
     
      Dim InsertCommand As New SqlCommand("StateAdmin_insert", conn)
            InsertCommand.CommandType = CommandType.StoredProcedure
            InsertCommand.Parameters.AddWithValue("@A_Link", StateRec.A_Link)

     

    Here is the error message when I try an insert a record.

    System.Data.SqlClient.SqlException was caught
      Class=16
      ErrorCode=-2146232060
      LineNumber=0
      Message=Procedure or function 'EstateAdmin_insert' expects parameter '@A_LINK', which was not supplied.
      Number=201
      Procedure=EstateAdmin_insert
      Server=WMWCAPP1\SQL2K8
      Source=.Net SqlClient Data Provider
      State=4
      StackTrace:
           at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
           at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
     

     

     Thanks for your suggestions !


     
     
     


     

      

    Wednesday, January 12, 2011 5:07 PM

Answers

  • User877341716 posted

    InsertCommand.Parameters.AddWithValue("@A_Link", StateRec.A_Link)
     

     

    Hi,

    Your parameter name and its datatype should match with the one defined in the stored procedure

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 13, 2011 9:13 AM