Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Adding new record to databse

  1. #1

    Thread Starter
    Addicted Member dim_kevin_as_human's Avatar
    Join Date
    Oct 2005
    Location
    Wisconsin
    Posts
    183

    Resolved [RESOLVED] [2005] Adding new record to databse

    this code is supposed to add a entry (folder name) into the database. When i run the program, everything goes smooth...it returns 1 as rows affected and doesn't error out or anything. my databound combobox comfirms it with my new folder, however when i close it out and launch it again, the folder is gone, and the database comfirms, no new records. I hope i'm not overlooking anything obvious but...

    VB Code:
    1. Private Sub AddFolder()
    2.  
    3.         StatusLabel.Text = "Creating New Folder ..."
    4.  
    5.         ' Display the FolderDialog form.  By setting the FolderID
    6.         ' property to 0, we're telling the dialog to essentially
    7.         ' go into "new folder" mode.  If we were to set the
    8.         ' FolderID > 0 then we'd be telling the dialog to go
    9.         ' into "folder edit" mode.
    10.  
    11.         Dim myFolderDialog As New FolderDialog()
    12.  
    13.         ' Dialog, go into "new folder" mode ...
    14.         myFolderDialog.FolderID = 0
    15.  
    16.  
    17.         Dim result As DialogResult
    18.         result = myFolderDialog.ShowDialog
    19.         If result = Windows.Forms.DialogResult.Cancel Then
    20.             StatusLabel.Text = "New folder operation cancelled."
    21.         End If
    22.  
    23.         If result = Windows.Forms.DialogResult.OK Then
    24.  
    25.             Dim folder As RssFeedsDataSet.FolderRow
    26.             folder = RssFeedsDataSet1.Folder.NewFolderRow
    27.  
    28.             folder.FolderName = myFolderDialog.FolderName
    29.  
    30.             'If BindingSource1.SupportsSearching <> True Then
    31.             '    MessageBox.Show("Cannot search the list.")
    32.             'Else
    33.             Dim foundIndex As Integer = FolderBindingSource.Find("FolderName", folder.FolderName)
    34.             If foundIndex > -1 Then
    35.                 MessageBox.Show("A fold already exsists by that name. Please Choose another name", "Folder already found", Nothing, MessageBoxIcon.Error)
    36.                 Call AddFolder()
    37.             Else
    38.                 Try
    39.                     RssFeedsDataSet1.Folder.AddFolderRow(folder)
    40.  
    41.                     Dim rowsAffected As Integer = 0
    42.                     rowsAffected = FolderTableAdapter.Update(folder)
    43.  
    44.                     If rowsAffected > 0 Then
    45.                         StatusLabel.Text = "New Folder Created - '" & myFolderDialog.FolderName & "'"
    46.                     Else
    47.                         StatusLabel.Text = "Problem creating new folder.  Could not save into the database."
    48.                     End If
    49.  
    50.                 Catch ex As Exception
    51.                     MessageBox.Show("Problem creating new folder: " & ex.Message)
    52.                 End Try
    53.  
    54.  
    55.             End If
    56.  
    57.  
    58.         End If
    59.         myFolderDialog = Nothing
    60.  
    61.     End Sub
    Dreaming men are haunted men.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: [2005] Adding new record to databse

    Are you using an SQL Server MDF file that you've added to your project? If so this is a source file like any other and will get copied to your output folder by default with each build, thus overwriting any changes you may previously have made. If this is the case then select the MDF file in the Solution Explorer, then go to the Properties window and change the Copy to Output Directory property to a more appropriate value. "Copy if newer" is the most likely candidate and probably should have been the default.

  3. #3

    Thread Starter
    Addicted Member dim_kevin_as_human's Avatar
    Join Date
    Oct 2005
    Location
    Wisconsin
    Posts
    183

    Re: [2005] Adding new record to databse

    Yes! "copy if newer" did the trick. kudos
    Dreaming men are haunted men.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width