Hi Phillip,
Thank you so much for the reply. After looking over your suggested reading
and reading some other posts I got the impression that the Edit/Delete
functions only work when you are using a Datasource attached to the
DatasourceId property. Is this correct? Based on that, I have redesigned the
for some using a SqlDataSource attached to the DatasourceId. But I'm getting
the following error when trying to update a row:
Procedure or function Admin_UpdatePOItem has too many arguments specified.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function
Admin_UpdatePOItem has too many arguments specified.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Now, I have setup the gridview as follows:
<asp:GridView ID="grdPOs" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px"
CellPadding="4" DataKeyNames="ItemId" Height="68px" PageSize="5"
Width="642px" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" DataSourceID="PODetailDataSource">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="ItemID" HeaderText="Item ID"
Visible="False" />
<asp:BoundField DataField="POrderId" HeaderText="PO Id"
Visible="False" />
<asp:BoundField DataField="Page" HeaderText="Page">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="CatalogId" HeaderText="Catalog #">
<ItemStyle HorizontalAlign="Right" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="ItemDescription"
HeaderText="Description">
<ItemStyle Width="250px" />
</asp:BoundField>
<asp:BoundField DataField="Qty" HeaderText="Qty">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="UnitPrice"
DataFormatString="{0:C}" HeaderText="UnitPrice">
<ItemStyle HorizontalAlign="Right" Width="70px" />
</asp:BoundField>
<asp:BoundField DataFormatString="{0:0.00}"
HeaderText="Total" InsertVisible="False" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="#FFFFCC" />
</asp:GridView>
And the datasource is as follows:
<asp:SqlDataSource ID="PODetailDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings
ODetailsConnectionString %>"
SelectCommand="admin_GetPODetails"
SelectCommandType="StoredProcedure" DeleteCommand="Admin_DeletePOItem"
DeleteCommandType="StoredProcedure" InsertCommand="Admin_AddPOItems"
InsertCommandType="StoredProcedure" UpdateCommand="Admin_UpdatePOItem"
UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="cmbPORequests"
Name="POrderId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp
arameter Name="ItemId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp
arameter Name="ItemID" Type="Int32" />
<asp
arameter Name="CatalogId" Type="String" />
<asp
arameter Name="ItemDescription" Type="String" />
<asp
arameter Name="Qty" Type="Int32" />
<asp
arameter Name="UnitPrice" Type="Decimal" />
<asp
arameter Name="Page" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp
arameter Name="POrderId" Type="Int32" />
<asp
arameter Name="CatalogeId" Type="String" />
<asp
arameter Name="ItemDescription" Type="String" />
<asp
arameter Name="Qty" Type="Int32" />
<asp
arameter Name="UnitPrice" Type="Decimal" />
<asp
arameter Name="Page" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
The Stored proc is written as follows:
CREATE PROCEDURE [dbo].[Admin_UpdatePOItem]
@ItemID int,
@CatalogId varchar(20),
@ItemDescription varchar(250),
@Qty int,
@UnitPrice money,
@Page varchar(10)
AS
Update OrderItems Set
CatalogId = @CatalogId,
ItemDescription = @ItemDescription,
Qty = @Qty,
UnitPrice = @UnitPrice,
Page = @Page
Where ItemID = @ItemID
GO
The research that I've done so far I have found that there is an extra
parameter, so I setup a function to remove the parameter but I still get the
error. Here is the code to delete.
'Serves to tell me what parameters and delete the extra one.
Protected Sub PODetailDataSource_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
PODetailDataSource.Updating
Dim param As DbParameter
Dim DeleteParam as DbParameter
Debug.WriteLine("Starting Test")
Debug.WriteLine("The command has " & e.Command.Parameters.Count.ToString
& " parameters altogether.")
For Each param In e.Command.Parameters
if param.ParameterName.ToString = "@POrderId" then
DeleteParam = param
End If
if param.ParameterName.ToString.Length > 1 then
Debug.WriteLine("parameter " & param.ParameterName.ToString & "
=> " & (param.Value.ToString & "") & "<br>")
end if
Next
if not isnothing(DeleteParam) then
e.Command.Parameters.Remove(DeleteParam)
end if
Debug.WriteLine("Starting Second Test")
Debug.WriteLine("The command has " & e.Command.Parameters.Count.ToString
& " parameters altogether.")
For Each param In e.Command.Parameters
if param.ParameterName.ToString = "@POrderId" then
DeleteParam = param
End If
if param.ParameterName.ToString.Length > 1 then
Debug.WriteLine("parameter " & param.ParameterName.ToString & "
=> " & (param.Value.ToString & "") & "<br>")
end if
Next
End Sub
After the code is run (before deleting the parameter) I get the following
parameter:
The command has 8 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescription => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
parameter @POrderId => 1<br> ****Param to remove *****
Starting Second Test
The command has 7 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescription => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
Sorry for the long message, but I figured you may need to know this info.
What do you think. Thanks for the help.
Michael