Solved

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

Posted on 2012-03-21
4
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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