Results 1 to 5 of 5

Thread: Saving settings to database - insert vs update

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Saving settings to database - insert vs update

    I want to use an Sqlite database to save certain program settings. I want the program to load the settings on startup & set the controls accordingly and then save the settings on program exit. This will basically setup the program with the last used settings when opened. I feel like I need to use an update statement to save the settings but that won't work on the first run of the program, because there won't be any settings in the table yet to update. Do I need to check first if the settings exist in the table and if they don't exist then do an insert & if they do exist then do an update? That seems like an inefficient way to do it. There's got to be a better way. Any suggestions?

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,517

    Re: Saving settings to database - insert vs update

    The easiest way is to include the initial default settings.

    If not, then you would certainly need to check if a setting exists before an update and if it doesn't then do an add. I wouldn't worry about inefficiency, unless your talking about 100,000 settings records.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Saving settings to database - insert vs update

    Quote Originally Posted by wes4dbt View Post
    The easiest way is to include the initial default settings.
    I actually did think about doing that way. Since I am creating the database & tables on first start of the program, it would pretty easy to just insert some default values for the settings. I just wanted to see how others might tackle the problem. I'm sure there are other ways to do it also. Thanks...

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Saving settings to database - insert vs update

    Quote Originally Posted by nbrege View Post
    I just wanted to see how others might tackle the problem. I'm sure there are other ways to do it also. Thanks...
    a) Either by doing an UPSERT if possible, or if not, b) then by writing a default record with default values...

    Since your'e creating the db... seems like b would be the easier/better choice.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Saving settings to database - insert vs update

    I would also tend to insert the default values at startup, when creating the database. Are you using default values for these settings when your app runs the first time? If so, that's even more reason to insert default values.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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