No value given for one or more required parameters

  • Thread starter Thread starter André
  • Start date Start date
A

André

Hi,

I created a button in order to delete all the records at once in a gridview.
But i get the error: No value given for one or more required parameters
Thanks
André

The aspx file contains:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..."
....
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
....
</asp:GridView>

<input id="Button1" type="submit" runat="server" value="Cancel all" />

The code-behind contains:
Protected Sub Button1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.ServerClick
x="this value"
SqlDataSource1.SelectParameters.Add("param1", x)
SqlDataSource1.DeleteCommand = "delete from mytable where field1 = @param1"
SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.Text
SqlDataSource1.Delete()
End Sub
 
Andre,

You have to faces, one is to delete the rows from your datasource
The second is to update that datasource to your database.

You are trying to do that in one time. But I don't not really know if you
want to delete them in the database according to your text.

Cor
 
Hi Cor, thanks for replying.

When a particular user starts the application, he sees in the gridview all
his personal record. He can delete one row at the time by clicking on the
'delete' link in the gridview. There is a DeleteCommand in the aspx file.
But i added a button in order to delete all his records at once. the code is
in the code-behind file.
The field after 'where ..' is his logon (gotten by the server-side
Request.ServerVariables("remote_user"). So only all his own records will be
deleted.

I thought that passing a parameter with the right value would work ...

Can you please tell me what to change in the code?

Thanks
André
 
I found it:
SqlDataSource1.DeleteCommand = "delete from mytable where field1 ='" & x &
"'"
 
Back
Top