Deleting Coresponding Row(s)
-
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)
-
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)
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.”
-
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.”
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
-
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)
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()
-
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
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"