Solved

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

Posted on 2012-03-21
4
320 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

21 Experts available now in Live!

Get 1:1 Help Now