PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET No value given for one or more required parameters

Reply

No value given for one or more required parameters

 
Thread Tools Rate Thread
Old 17-06-2006, 09:24 PM   #1
André
Guest
 
Posts: n/a
Default No value given for one or more required parameters


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



  Reply With Quote
Old 18-06-2006, 07:34 AM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: No value given for one or more required parameters

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


"André" <sdsds@sds.sdf> schreef in bericht
news:%23wOzkwkkGHA.3512@TK2MSFTNGP03.phx.gbl...
> 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
>
>
>



  Reply With Quote
Old 18-06-2006, 10:33 AM   #3
André
Guest
 
Posts: n/a
Default Re: No value given for one or more required parameters

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é





"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:uF4nFEqkGHA.1264@TK2MSFTNGP05.phx.gbl...
> 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
>
>
> "André" <sdsds@sds.sdf> schreef in bericht
> news:%23wOzkwkkGHA.3512@TK2MSFTNGP03.phx.gbl...
> > 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
> >
> >
> >

>
>



  Reply With Quote
Old 18-06-2006, 10:40 AM   #4
André
Guest
 
Posts: n/a
Default Re: No value given for one or more required parameters

I found it:
SqlDataSource1.DeleteCommand = "delete from mytable where field1 ='" & x &
"'"



"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:uF4nFEqkGHA.1264@TK2MSFTNGP05.phx.gbl...
> 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
>
>
> "André" <sdsds@sds.sdf> schreef in bericht
> news:%23wOzkwkkGHA.3512@TK2MSFTNGP03.phx.gbl...
> > 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
> >
> >
> >

>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off