Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-21
4
Medium Priority
?
347 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 1500 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

596 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