Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Deleting Coresponding Row(s)

Deleting Coresponding Row(s)

Scheduled Pinned Locked Moved Visual Basic
databasecsharphelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustinRiggs
    wrote on last edited by
    #1

    Hi if anyone could help I would appreciate it. I have a database with a Movies Table, Casting Table, and Actor Table. Movie Table has MovieID Casting Table has MovieID , and ActorID Actor Table has ActorID This code deletes a row from the movies table(using a datagrid in vb.net), I need all the rows in the Casting table with the same MovieID to also be deleted. Any help would be appreciated!! Dim result As String Dim i As Integer i = MovieDataGridView.CurrentRow.Index result = MsgBox("Are you sure you want to delete this movie?", MsgBoxStyle.OkCancel) If result = vbOK Then If MovieDataGridView.Rows.Count = 1 Then MsgBox("You must leave one movie in database!!") Else Me.MovieDataGridView.Rows.Remove(Me.MovieDataGridV iew.SelectedRows(0)) End If Else End If Me.Validate() Me.MovieBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.MovieProjectDa taSet)

    H J 2 Replies Last reply
    0
    • J JustinRiggs

      Hi if anyone could help I would appreciate it. I have a database with a Movies Table, Casting Table, and Actor Table. Movie Table has MovieID Casting Table has MovieID , and ActorID Actor Table has ActorID This code deletes a row from the movies table(using a datagrid in vb.net), I need all the rows in the Casting table with the same MovieID to also be deleted. Any help would be appreciated!! Dim result As String Dim i As Integer i = MovieDataGridView.CurrentRow.Index result = MsgBox("Are you sure you want to delete this movie?", MsgBoxStyle.OkCancel) If result = vbOK Then If MovieDataGridView.Rows.Count = 1 Then MsgBox("You must leave one movie in database!!") Else Me.MovieDataGridView.Rows.Remove(Me.MovieDataGridV iew.SelectedRows(0)) End If Else End If Me.Validate() Me.MovieBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.MovieProjectDa taSet)

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I will leave answering your question to those with more knowledge than I. However, If after waiting a few hours (remember this is the weekend) you have not received an answer, I would suggest this would be better asked in the General Database forum. Also, it seems strange to insist that there be at least one movie in the table. Care to share the reason for this?

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      J 1 Reply Last reply
      0
      • H Henry Minute

        I will leave answering your question to those with more knowledge than I. However, If after waiting a few hours (remember this is the weekend) you have not received an answer, I would suggest this would be better asked in the General Database forum. Also, it seems strange to insist that there be at least one movie in the table. Care to share the reason for this?

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        J Offline
        J Offline
        JustinRiggs
        wrote on last edited by
        #3

        Yeah it is strange to have to keep one movie in the table. It is because I have another problem that I will have to deal with later. This program is for a school project:) See here when I add a new movie it counts the rows -1 and if there are no rows I get a no nulls allowed in movieID error. So for now I took that problem away by cheating with the msgbox!! Dim rowcount As Integer = Form1.MovieDataGridView.Rows.Count             'Get the value of the last movie ID             x = Form1.MovieDataGridView.Item(0, rowcount - 1).Value             'Add 1 to the value of the last movie ID             x += 1             'Add new row to the datagridview's datasource             Form1.MovieDataGridView.DataSource.addnew()             'Set the value of column 1 on the new row             Form1.MovieDataGridView.Rows(rowcount).Cells(0).Value = x             'Set the value of column 2 on the new row to the data in the Title textbox             Form1.MovieDataGridView.Rows(rowcount).Cells(1).Value = txtTitle.Text

        N 1 Reply Last reply
        0
        • J JustinRiggs

          Hi if anyone could help I would appreciate it. I have a database with a Movies Table, Casting Table, and Actor Table. Movie Table has MovieID Casting Table has MovieID , and ActorID Actor Table has ActorID This code deletes a row from the movies table(using a datagrid in vb.net), I need all the rows in the Casting table with the same MovieID to also be deleted. Any help would be appreciated!! Dim result As String Dim i As Integer i = MovieDataGridView.CurrentRow.Index result = MsgBox("Are you sure you want to delete this movie?", MsgBoxStyle.OkCancel) If result = vbOK Then If MovieDataGridView.Rows.Count = 1 Then MsgBox("You must leave one movie in database!!") Else Me.MovieDataGridView.Rows.Remove(Me.MovieDataGridV iew.SelectedRows(0)) End If Else End If Me.Validate() Me.MovieBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.MovieProjectDa taSet)

          J Offline
          J Offline
          JustinRiggs
          wrote on last edited by
          #4

          I got it to work like this, I added a new query called GetDatabyDcast to my casting datatable that says DELETE FROM Casting WHERE MovieID =@MovieID then I added that into the delete button. This probably isnt the best way to do it but it got the job done. If you know a better way, then let me know please. Thanks Dim result As String             Dim i As Integer             i = MovieDataGridView.CurrentRow.Index             result = MsgBox("Are you sure you want to delete this movie?", MsgBoxStyle.OkCancel)             If result = vbOK Then                   If MovieDataGridView.Rows.Count = 1 Then                         MsgBox("You must leave one movie in database!!")                   Else                         Dim s As Integer                         s = Me.MovieDataGridView.CurrentRow.Index                         Dim a As String = Me.MovieDataGridView.Item(0, s).Value.ToString                         a = a                         Dim ta As New MovieProjectDataSetTableAdapters.CastingTableAdapter                         Dim tbl As MovieProjectDataSet.CastingDataTable                         tbl = ta.GetDataByDcast(a)                         Form3.CastingTableAdapter.Fill(Me.MovieProjectDataSet.Casting)                         Form3.Validate()                         Form3.CastingDataGridView.EndEdit()

          1 Reply Last reply
          0
          • J JustinRiggs

            Yeah it is strange to have to keep one movie in the table. It is because I have another problem that I will have to deal with later. This program is for a school project:) See here when I add a new movie it counts the rows -1 and if there are no rows I get a no nulls allowed in movieID error. So for now I took that problem away by cheating with the msgbox!! Dim rowcount As Integer = Form1.MovieDataGridView.Rows.Count             'Get the value of the last movie ID             x = Form1.MovieDataGridView.Item(0, rowcount - 1).Value             'Add 1 to the value of the last movie ID             x += 1             'Add new row to the datagridview's datasource             Form1.MovieDataGridView.DataSource.addnew()             'Set the value of column 1 on the new row             Form1.MovieDataGridView.Rows(rowcount).Cells(0).Value = x             'Set the value of column 2 on the new row to the data in the Title textbox             Form1.MovieDataGridView.Rows(rowcount).Cells(1).Value = txtTitle.Text

            N Offline
            N Offline
            Noctris
            wrote on last edited by
            #5

            Hmm.. Small Reaction. As i understand, you are actually handeling your "MovieID" in code. You should let your database handle this and just request what id it gave to the last record you inserted in the database ( syntax might depend on the database you are uding) About deleting the cast records related to the movie: you actually do the right thing ;-) I don't see any other way then to simple delete all records in that table related to the movie you have deleted.

            Do Or Don't, there is no "try catch ex as exception end try"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups