how to execute the DeleteCommand in code-behind?

Discussion in 'ASP .Net Web Controls' started by phil, Jun 1, 2006.

  1. phil

    phil Guest

    Hi,

    The connection and DeleteCommand of a gridview are defined in the aspx file
    like this:
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb"
    ProviderName="System.Data.OleDb"
    DeleteCommand="delete from mytable where [nr] = @nr" >
    </asp:SqlDataSource>

    Now i created a button (button1) for deleting all records at once. So i
    defined a new DeleteCommand in the code-behind. My problem is how to execute
    that new command.
    Look what i tried in the code-behind file:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    SqlDataSource1.DeleteCommand = "delete from mytable"
    SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.Text
    End Sub

    I can't find an 'execute' or similar ...
    Thanks fro helping
    Phil
     
    phil, Jun 1, 2006
    #1
    1. Advertising

  2. phil

    Riki Guest

    SqlDataSource1.Delete()

    --

    Riki

    "phil" <> wrote in message
    news:...
    > Hi,
    >
    > The connection and DeleteCommand of a gridview are defined in the aspx
    > file
    > like this:
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=c:\mydb.mdb"
    > ProviderName="System.Data.OleDb"
    > DeleteCommand="delete from mytable where [nr] = @nr" >
    > </asp:SqlDataSource>
    >
    > Now i created a button (button1) for deleting all records at once. So i
    > defined a new DeleteCommand in the code-behind. My problem is how to
    > execute
    > that new command.
    > Look what i tried in the code-behind file:
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > SqlDataSource1.DeleteCommand = "delete from mytable"
    > SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.Text
    > End Sub
    >
    > I can't find an 'execute' or similar ...
    > Thanks fro helping
    > Phil
    >
    >
     
    Riki, Jun 1, 2006
    #2
    1. Advertising

  3. phil

    phil Guest

    So obvious ...
    Many thanks

    "Riki" <> wrote in message
    news:...
    > SqlDataSource1.Delete()
    >
    > --
    >
    > Riki
    >
    > "phil" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > The connection and DeleteCommand of a gridview are defined in the aspx
    > > file
    > > like this:
    > > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > > ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
    > > Source=c:\mydb.mdb"
    > > ProviderName="System.Data.OleDb"
    > > DeleteCommand="delete from mytable where [nr] = @nr" >
    > > </asp:SqlDataSource>
    > >
    > > Now i created a button (button1) for deleting all records at once. So i
    > > defined a new DeleteCommand in the code-behind. My problem is how to
    > > execute
    > > that new command.
    > > Look what i tried in the code-behind file:
    > > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Button1.Click
    > > SqlDataSource1.DeleteCommand = "delete from mytable"
    > > SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.Text
    > > End Sub
    > >
    > > I can't find an 'execute' or similar ...
    > > Thanks fro helping
    > > Phil
    > >
    > >

    >
    >
     
    phil, Jun 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    592
    Alphonse Giambrone
    Jun 28, 2003
  2. Peter Afonin
    Replies:
    2
    Views:
    457
    Peter Afonin
    Nov 19, 2003
  3. Kamal Ahmed
    Replies:
    1
    Views:
    5,214
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Oct 25, 2005
  4. phil
    Replies:
    2
    Views:
    4,826
  5. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    490
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
Loading...

Share This Page