Solved

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

Posted on 2012-03-21
4
316 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
Comment Utility
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
Comment Utility
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
Comment Utility
se this link hope it helps

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

Author Closing Comment

by:Vitech
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now