Results 1 to 3 of 3

Thread: delete record from 2 tables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    274

    delete record from 2 tables

    INstead of this, any better way to delete record from 2 tables in a faster way?


    m_con = New SQLiteConnection(ConfigurationManager.ConnectionStrings("constr").ToString)
    m_con.Open()
    m_sqlstate = "" : m_sqlstate = "SELECT * FROM cust_userdetails"
    m_da = New SQLiteDataAdapter(m_sqlstate, m_con)
    m_cmdbuilder = New SQLiteCommandBuilder(m_da)
    m_ds = New DataSet
    m_da.Fill(m_ds)
    m_ds.Tables(0).PrimaryKey = New DataColumn() {m_ds.Tables(0).Columns("member_id")}
    m_dr = m_ds.Tables(0).Rows.Find(m_memberid)
    If m_dr IsNot Nothing Then m_dr.Delete()
    m_da.Update(m_ds)

    m_sqlstate = "" : m_sqlstate = "SELECT * FROM cust_license"
    m_da = New SQLiteDataAdapter(m_sqlstate, m_con)
    m_cmdbuilder = New SQLiteCommandBuilder(m_da)
    m_ds = New DataSet
    m_da.Fill(m_ds)
    m_ds.Tables(0).PrimaryKey = New DataColumn() {m_ds.Tables(0).Columns("member_id")}
    m_ds.Tables(0).PrimaryKey = New DataColumn() {m_ds.Tables(0).Columns("member_id")}
    m_dr = m_ds.Tables(0).Rows.Find(m_memberid)
    If m_dr IsNot Nothing Then m_dr.Delete()
    m_da.Update(m_ds)

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: delete record from 2 tables

    You can write a stored procedure to delete all records from child table and then delete records from master table.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: delete record from 2 tables

    Run an ExecuteNonQuery against the tables

    DELETE FROM Tablename


    (This is assuming you want to delete all records in the tables, which is what it seems like you're doing)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width