sueszyq Posted December 11, 2003 Posted December 11, 2003 (edited) I am having trouble adding a record to a dataset. I get an error that the Title already exists. Please Help! Here is the code: Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click 'declare a new row in the table Dim newRow As DataRow = CDDataSet.CD_Collection.NewRow 'Change button text for add or cancel 'put current record number in a variable If AddButton.Text = "&Cancel" Then AddButton.Text = "&Add" 'BindingContext(CDDataSet, "CD Collection").Position = intCurRecNum If mblnAdding = "True" Then Try 'add a new row to the dataset newRow("Artist/Group") = ArtistTextbox.Text ValidTitle() newRow("CD Title") = TitleTextbox.Text newRow("Year") = Val(YearTextbox.Text) newRow("Label") = LabelTextbox.Text newRow("Category") = CategoryTextbox.Text Catch ex As Exception MessageBox.Show("Unable to add record", "CD Collection") End Try mblnAdding = "False" RecCountLabel.Text = "Record Added at end of table" End If LockTextBoxes() EnableNav() SaveButton.Enabled = "False" EditButton.Enabled = "True" DelButton.Enabled = "True" Else 'intCurRecNum = BindingContext(CDDataSet, "CD Collection").Position mblnAdding = "True" AddButton.Text = "&Cancel" UnlockTextBoxes() DisableNav() 'reset enable for buttons EditButton.Enabled = "False" DelButton.Enabled = "False" SaveButton.Enabled = "True" End If End Sub Edited December 11, 2003 by Robby Quote
Moderators Robby Posted December 11, 2003 Moderators Posted December 11, 2003 First thing is place Option Strict On and Option Explicit On at the top of each code page. Then remove all the quotes surrounding True and False values. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.