10 Replies - 335 Views - Last Post: 03 March 2012 - 10:43 AM Rate Topic: -----

#1 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

How to delete rows which are linked in a relationship

Posted 03 March 2012 - 05:01 AM

hi

i have a simple relationship which is shown in the link below

http://www.flickr.co...N06/6948010043/

after doing much research i cannot find a proper way of deleting rows which are linked in all 3 tables.

could someone guide me on the best way of doing this.

This is the code i am using currently

strsql = "delete *  from  cg_security_user_right  where user_id=@field1 &  right_id=@field2  "
        Dim objcmd As New System.Data.OleDb.OleDbCommand(strsql, acsconn) ' the oledbcommand
        With objcmd
            .Parameters.AddWithValue("@field1", TextBox1.Text)
            .Parameters.AddWithValue("@field2", TextBox2.Text)



        End With
        Dim result As Integer = 0
        result = objcmd.ExecuteNonQuery()
        objcmd.Dispose()
        MsgBox(result & " Row Deleted")
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: How to delete rows which are linked in a relationship

#2 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 07:38 AM

ok this is confusing me right now when i run the query " DELETE FROM cg_security_user_right " threw a query builder it delets the records but when i put a where in it doesnt delete why can that be
Was This Post Helpful? 0
  • +
  • -

#3 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 09:23 AM

i been trying to solve this problem since morning its now 430 and i cannot see why it is not working please could some1 suggest why it is not working.

The relationship works correctly. When i delete the user_id which is linked two a role_id. it removes it in all 3 tables

why does this code not work

  connect7()
    End Sub
    Sub connect7()
        acsconn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\HP Sajad\Documents\Visual Studio 2010\Projects\SupplyChainSystem\SupplyChainSystem\security.mdb"
        acsconn.Open()
        If acsconn.State = ConnectionState.Open Then



        End If
        MsgBox("Connected")

        strsql = "DELETE FROM cg_security_user where user_id=@field1  "
        Dim objcmd As New System.Data.OleDb.OleDbCommand(strsql, acsconn) ' the oledbcommand
        With objcmd
            .Parameters.AddWithValue("@field1", TextBox1.Text)



        End With
        Dim result As Integer = 0
        result = objcmd.ExecuteNonQuery()
        objcmd.Dispose()
        MsgBox(result & " Row Deleted")
    End Sub


Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6463
  • View blog
  • Posts: 23,497
  • Joined: 12-June 08

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 09:40 AM

Please do not open duplicate topics.. Merging them..
Was This Post Helpful? 0
  • +
  • -

#5 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 09:47 AM

sorry please help im really stuck onn this code
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6463
  • View blog
  • Posts: 23,497
  • Joined: 12-June 08

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 09:53 AM

Is it giving you an error?

Your line 11 should be *IN* the 06/10 if statement.

It's preferred you wrap your execute statement in a try/catch. You know - in case you get some odd error.

Try that.
Was This Post Helpful? 0
  • +
  • -

#7 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 09:55 AM

no there no error its runing fine but the data in the db is not being deleted
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6463
  • View blog
  • Posts: 23,497
  • Joined: 12-June 08

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 10:02 AM

Just do it! Geeze if you want me to debug by proxy then assuage my concerns! Hahaha..
Was This Post Helpful? 0
  • +
  • -

#9 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 10:08 AM

still it not doing it
it still says 0 rows deleted

why can this be
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6463
  • View blog
  • Posts: 23,497
  • Joined: 12-June 08

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 10:16 AM

Is your textbox values right? I mean is there an extra space or something you are not trimming off?
Was This Post Helpful? 0
  • +
  • -

#11 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: How to delete rows which are linked in a relationship

Posted 03 March 2012 - 10:43 AM

still the same i dont no wats happened 2 it its just delete that doesnt want to work
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1