how to execute the DeleteCommand in code-behind?

Discussion in 'ASP .Net' 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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    826
    Alphonse Giambrone
    Jun 28, 2003
  2. Marcel Balcarek
    Replies:
    4
    Views:
    11,121
    Bin Song
    Dec 5, 2003
  3. Daniel Manes

    Code-Behind Pain in the Behind!

    Daniel Manes, Jun 10, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    943
  4. Kamal Ahmed
    Replies:
    1
    Views:
    5,409
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Oct 25, 2005
  5. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    719
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  6. JB
    Replies:
    2
    Views:
    3,594
    Cubaman
    Aug 2, 2010
  7. Troy

    User control code behind does not execute

    Troy, Oct 22, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    171
    Victor Garcia Aprea [MVP]
    Oct 23, 2003
  8. phil

    how to execute the DeleteCommand in code-behind?

    phil, Jun 1, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    300
Loading...