locked
An SqlParameter with ParameterName 'ServerID' is not contained by this SqlParameterCollection. RRS feed

  • Question

  • User1866404511 posted

    Hi dears,

    I got this error when I want to read output value from SQL DB.

    An SqlParameter with ParameterName 'ServerID' is not contained by this SqlParameterCollection.

    Markup:

    <asp:SqlDataSource ID="SDS_DisplayRecodInDetailsView" runat="server"
    ConnectionString="<%$ ConnectionStrings:ServersInfoConnectionString %>"
    SelectCommand="SP_DisplayRecodInDetailsView" SelectCommandType="StoredProcedure"
    InsertCommand="SP_InsertNewRecord" InsertCommandType="StoredProcedure" UpdateCommand="SP_UpdateRecord"
    oninserted="SDS_DisplayRecodInDetailsView_Inserted">
    <InsertParameters>
    <asp:Parameter Direction="Output" Name="Counter" Type="Int32" />
    <asp:Parameter Name="ServerID" Type="String" />
    <asp:Parameter Name="AssetNo" Type="String" />
    </InsertParameters>
    <SelectParameters>
     <asp:ControlParameter ControlID="Grd_ServersInfo" Name="ServerID" PropertyName="SelectedValue"
     Type="Int32" /> </SelectParameters>
     </asp:SqlDataSource>


    code behind

     protected void SDS_DisplayRecodInDetailsView_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    
    {
    
    OutputValue = (int)((IDbDataParameter)e.Command.Parameters["Counter"]).Value;
    
    lbl_Message.Text = OutputValue.ToString();
    
    }



    Thanks a lot

    Friday, August 12, 2011 8:23 AM

Answers

  • User1866404511 posted

    I found this solution:

    lbl_Message.Text = Convert.ToString(e.Command.Parameters["Counter"].Value);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 13, 2011 2:53 PM

All replies

  • User1100692814 posted

    Hi

    Is the selected CommandField set for Grd_ServersInfo?

    Hope this helps.

    D

    EX:

    <asp:CommandField ShowSelectButton="True" SelectText="View Details" />
    Friday, August 12, 2011 8:49 AM
  • User1866404511 posted

    Yes, It already sets for gridview.

    Any other suggestions?????

    Friday, August 12, 2011 9:14 AM
  • User1100692814 posted

    Please post the code for the GridViews. Also, are you sure the ServerID is being returned from the Select query?

    /D

    Friday, August 12, 2011 9:16 AM
  • User1866404511 posted

    Thank you once again, Here is the code :

    <asp:GridView ID="Grd_ServersInfo" runat="server" DataSourceID="SDS_ServersInfo"
    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ServerID"
    PageSize="5" EmptyDataText="No Records found" AutoGenerateSelectButton="True">
    <Columns>
    <asp:BoundField DataField="Counter" HeaderText="Counter" InsertVisible="False" ReadOnly="True"
    SortExpression="Counter" />
    <asp:BoundField DataField="ServerID" HeaderText="ServerID" ReadOnly="True" SortExpression="ServerID" />
    <asp:BoundField DataField="AssetNo" HeaderText="AssetNo" SortExpression="AssetNo" />
    <asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber" SortExpression="SerialNumber" />
    <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
    <asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
    <asp:BoundField DataField="ModelName" HeaderText="ModelName" SortExpression="ModelName" />
    <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" />
    <asp:BoundField DataField="Project" HeaderText="Project" SortExpression="Project" />
    <asp:BoundField DataField="AssetType" HeaderText="AssetType" SortExpression="AssetType" />
    <asp:BoundField DataField="ServerYesNo" HeaderText="ServerYesNo" SortExpression="ServerYesNo" />
    <asp:BoundField DataField="Technology" HeaderText="Technology" SortExpression="Technology" />
    <asp:BoundField DataField="Row" HeaderText="Row" SortExpression="Row" />
    <asp:BoundField DataField="Grid" HeaderText="Grid" SortExpression="Grid" />
    </Columns>
    <PagerTemplate>
    <asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex
    + 1 %>">
    </asp:Label>/
    <asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>">
    </asp:Label>
    <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
    Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0
    %>">First</asp:LinkButton>
    <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
    CommandName="Page" Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">Previous
    </asp:LinkButton>
    <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
    Enabled="<%# ((GridView)Container.NamingContainer).PageIndex !=
    ((GridView)Container.NamingContainer).PageCount - 1 %>">Next
    </asp:LinkButton>
    <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
    Enabled="<%# ((GridView)Container.NamingContainer).PageIndex !=
    ((GridView)Container.NamingContainer).PageCount - 1 %>">Last
    </asp:LinkButton>
    </PagerTemplate>
    <SelectedRowStyle BackColor="#99CCFF" />
    </asp:GridView>
    Friday, August 12, 2011 9:22 AM
  • User1100692814 posted

    Try removing the AutoGenerateSelectButton property and set the column:

    <asp:CommandField ShowSelectButton="True" SelectText="View Details" />

    Hope it works.

    Also, give this a look.

    D

    Friday, August 12, 2011 9:31 AM
  • User1866404511 posted

    Thanks a lot Dave, It's seems going to work but small problem:

    When the execution reach this line:

    OutputValue = (int)((IDbDataParameter)e.Command.Parameters[0]).Value; 

    it's give me this error :

    Specified cast is not valid.

    Friday, August 12, 2011 4:28 PM
  • User1866404511 posted

    I found this solution:

    lbl_Message.Text = Convert.ToString(e.Command.Parameters["Counter"].Value);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 13, 2011 2:53 PM