CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2005
    Posts
    151

    Added a new record in my database, but after rebuild, the record is gone

    I once had this problem but I can't seem to fix it again :

    When I run my database-application and in a certain table I add a new record.
    The record stays in the table, even when I exit the application and rerun it.
    But when I look at the table data in the database explorer the record doesn't show up.
    When I do a rebuild solution, the record doesn't show up again in the application.

    I have set the property "copy to output directory" to "Copy if newer" for both the database and the dataset (.mdf and .xsd)

    Am I still doing something else wrong?

    edit : I looked at my connection string and the .mdf file is in my main project directory and not in any bin or debug directory. I think I have to change the connection string, but I can't chnage it through the property window. (Its' greyed out)
    Last edited by da_cobra; January 6th, 2008 at 01:30 PM.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Added a new record in my database, but after rebuild, the record is gone

    I'm not sure if you want the record to be persistent or not.

    If you do, then set the copy options to 'never copy' and change the connection string to point to the full path of the .mdb file in the project. Also make sure you delete any old .mdb files in the debug or release folders.

    If you don't want the data persistent, then change the copy options to 'always copy' and make sure the connection string points to the .mdb file located in the debug or release folder. You can make sure the program is not using the .mdb in the project folder by starting the program and then temporarily move the .mdb file from the project. If you can move the file, it means the program is still using the file from the project.

  3. #3
    Join Date
    Apr 2005
    Posts
    151

    Re: Added a new record in my database, but after rebuild, the record is gone

    thx for the reply, but I have 2 comments :

    1) since english isn't my mother language : persistent = ???

    2) Like I said in my first post : I can't change the connection string through the properties of the .mdf file, because the string is greyed out.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Added a new record in my database, but after rebuild, the record is gone

    Persistent justs means 'saved'.

    Can you change the connection string in the dataset by setting a property at runtime?

  5. #5
    Join Date
    Apr 2005
    Posts
    151

    Re: Added a new record in my database, but after rebuild, the record is gone

    How do I change the connection string by setting the property @ runtime?

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Added a new record in my database, but after rebuild, the record is gone

    Quote Originally Posted by da_cobra
    How do I change the connection string by setting the property @ runtime?
    Post your code that opens and uses the dataset.

  7. #7
    Join Date
    Apr 2005
    Posts
    151

    Re: Added a new record in my database, but after rebuild, the record is gone

    ok, maybe I'm stupid but where can I find that code?

    I added my dataset through the "add new item" => "sql database".
    (Right mouse button on my project name in the solution explorer.)

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Added a new record in my database, but after rebuild, the record is gone

    No problem. Up until now, I had never used the add 'SQL Database' item either.

    When you add the db, an app.config file gets created for you (if one already doesn't exist).

    Inside the app.config, you find a ConnectionStrings section with the connection for the db. Just modify the path here.

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

Featured