Hiya, I am needing to add a Speaker ID and Production ID to an associative table based on a production that was previously created, based on the title of the production and every selected Speaker in a listbox.
The following code functions, but only selects the first occurance and then adds multiple duplicate entries to the table (based on how many items were selected).
I have also tried this code, but recieve the "Public member 'Selected' on type 'DataRowView' not found" exception.
This is the code that the LoadAddProducti on_Speaker() function is calling:
Any ideas? Thanks
The following code functions, but only selects the first occurance and then adds multiple duplicate entries to the table (based on how many items were selected).
Code:
For Each objDataRowView As DataRowView In lstSpeakers.SelectedItems LoadAddProduction_Speaker() Next
Code:
For i As Integer = 0 To lstSpeakers.Items.Count - 1 If Me.lstSpeakers.Items(i).Selected Then LoadAddProduction_Speaker() End If Next i
Code:
Public Shared Function AddProduction_Speaker() As OdbcCommand Dim con As New OdbcConnection Dim objcommand As OdbcCommand = New OdbcCommand() con = New OdbcConnection(dc) objcommand.Connection = con objcommand.CommandText = "INSERT INTO Production_Speaker (Speaker_ID, Production_ID) SELECT Speaker.Speaker_ID, Production.Production_ID FROM Production, Speaker WHERE Speaker.Speaker_FullName = '" & MediaCenter.frmMediaCenter.lstSpeakers.Text & "' AND Production.Title = '" & MediaCenter.frmMediaCenter.txtTitle.Text & "'" objcommand.CommandType = CommandType.Text con.Open() Try objcommand.ExecuteNonQuery() Catch err As Exception MessageBox.Show(err.Message) Finally If Not con Is Nothing Then con.Close() End If End Try End Function
Comment