Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by Robby

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...