Solved

No value given for one or more required parameters. . in ASP GridView

Posted on 2012-03-21
4
323 Views
Last Modified: 2012-08-13
I have an ASP Grid linked to a simple database (Code below)

When I update or delete I get the following error

"No value given for one or more required parameters."

The error seems to be due to missing parameters becaause if I hard code the update command with this

 UpdateCommand="UPDATE [Users] SET [Level] = 'test', [PrintService] = 'test', [UserPassword] = 'test', [User_Name] = 'test, [CompanySID] = 'test' WHERE (([Pkey] = 1) OR ([Pkey] IS NULL AND ? IS NULL))">


It all works fine and the database is updated, so it must be that the parameters are not being passed but I cannot see where I am going wrong.

Thanks in advanvce for your help.



Nigel




<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                    AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CellPadding="4"
                    DataSourceID="Users" EnableModelValidation="True"
                    ForeColor="#333333" GridLines="None" DataKeyNames="Pkey"
                    AllowSorting="True">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="Pkey" HeaderText="Pkey"
                            SortExpression="Pkey" />
                        <asp:BoundField DataField="Level" HeaderText="Level" SortExpression="Level" />
                        <asp:BoundField DataField="PrintService" HeaderText="PrintService"
                            SortExpression="PrintService" />
                        <asp:BoundField DataField="UserPassword" HeaderText="UserPassword"
                            SortExpression="UserPassword" />
                        <asp:BoundField DataField="User_Name" HeaderText="User_Name"
                            SortExpression="User_Name" />
                        <asp:BoundField DataField="CompanySID" HeaderText="CompanySID"
                            SortExpression="CompanySID" />
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:AccessDataSource ID="Users" runat="server" DataFile="~/App_Data/Users.mdb"
                    DeleteCommand="DELETE FROM Users WHERE ((Pkey = ?) OR (Pkey IS NULL AND ? IS NULL))"
                    InsertCommand="INSERT INTO [Users] ([Level], [PrintService], [UserPassword], [User_Name], [CompanySID], [Pkey]) VALUES (?, ?, ?, ?, ?, ?)"
                    SelectCommand="SELECT [Level], [PrintService], [UserPassword], [User_Name], [CompanySID], [Pkey] FROM [Users]"
                    UpdateCommand="UPDATE [Users] SET [Level] = ?, [PrintService] = ?, [UserPassword] = ?, [User_Name] = ?, [CompanySID] = ? WHERE (([Pkey] = ?) OR ([Pkey] IS NULL AND ? IS NULL))">
                    <DeleteParameters>
                        <asp:Parameter Name="Pkey" Type="Int32" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="Level" Type="String" />
                        <asp:Parameter Name="PrintService" Type="String" />
                        <asp:Parameter Name="UserPassword" Type="String" />
                        <asp:Parameter Name="User_Name" Type="String" />
                        <asp:Parameter Name="CompanySID" Type="String" />
                        <asp:Parameter Name="Pkey" Type="Int32" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Level" Type="String" />
                        <asp:Parameter Name="PrintService" Type="String" />
                        <asp:Parameter Name="UserPassword" Type="String" />
                        <asp:Parameter Name="User_Name" Type="String" />
                        <asp:Parameter Name="CompanySID" Type="String" />
                        <asp:Parameter Name="Pkey" Type="Int32" />
                    </UpdateParameters>
                </asp:AccessDataSource>
0
Comment
Question by:Vitech
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 37746500
GridView Examples for ASP.NET 2.0: Deleting a GridView's Underlying Data
http://msdn.microsoft.com/en-us/library/ms972940.aspx
0
 
LVL 1

Author Comment

by:Vitech
ID: 37746531
That is pretty much what I have done only it's with an Access database not SQL
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 37746549
se this link hope it helps

http://forums.asp.net/t/1717508.aspx/1
0
 
LVL 1

Author Closing Comment

by:Vitech
ID: 37746591
Thanks,

found the issue in that post, beacuase I am using ? for the paramters the number of ? needs to match exactly to the number of parameters so I need to remove the OR ([Pkey] IS NULL AND ? IS NULL) in the update and delete commands

All works now.
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question