Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:19:56+00:00 2026-06-04T11:19:56+00:00

After much searching trying to find the best solution to using an embedded DB

  • 0

After much searching trying to find the best solution to using an embedded DB in my WPF app, I finally settled on/discovered the ease of using an MS Access DB. I had played around with SQL, but basically kept running into errors and problems that Access ultimately solved. So in order to use the DB once imported, I simply dragged the DataSet onto the WPF window, and VS generated a heap of code that allowed access. It works beautifully.

There is only one problem though, that being that the ZipCode table lookup causes the program to stall for 4-5 seconds, including hanging between keypresses. This takes some of the ease of use away, and I would like to find a way to speed this up.

I thought of using a BackgroundWorker, but I can’t seem to figure out a way to pass the commands to it at only the appropriate times. I’m not even sure if this is the best solution, or if there is another way to increase the speed.

In the DB file, the zipcodes functions as the Primary Key, and I have both columns (zipcode & location) indexed, also this didn’t seem to improve performance all that much. The two functions below are accessed through the OnTextChanged event of various textboxes.

Any suggestions will be greatly appreciated.

public void LocateZipCode(TextBox source, TextBox destination)
    {
        LocationsDataSet locationsDataSet = ((LocationsDataSet)this.FindResource("locationsDataSet"));

        // Load data into the table ZipCodes. You can modify this code as needed.
        LocationsDataSetTableAdapters.ZipCodesTableAdapter locationsDataSetZipCodesTableAdapter = new LocationsDataSetTableAdapters.ZipCodesTableAdapter();
        locationsDataSetZipCodesTableAdapter.Fill(locationsDataSet.ZipCodes);
        CollectionViewSource zipCodesViewSource = ((CollectionViewSource)(this.FindResource("zipCodesViewSource")));
        zipCodesViewSource.View.MoveCurrentToFirst();

        try
        {
            if (source.Text.Length == 5)
            {
                destination.Text = locationsDataSet.ZipCodes.FindByZipCode(source.Text).Location.ToString();
            }                
        }
        catch (NullReferenceException)
        {

        }
    }

    #region Area Code Lookup
    public void LocateAreaCode(TextBox source, TextBox destination, TextBox destination2 = null)
    {
        LocationsDataSet locationsDataSet = ((LocationsDataSet)(this.FindResource("locationsDataSet")));

        // Load data into the table AreaCodes. You can modify this code as needed.
        LocationsDataSetTableAdapters.AreaCodesTableAdapter locationsDataSetAreaCodesTableAdapter = new LocationsDataSetTableAdapters.AreaCodesTableAdapter();
        locationsDataSetAreaCodesTableAdapter.Fill(locationsDataSet.AreaCodes);
        CollectionViewSource areaCodesViewSource = ((CollectionViewSource)(this.FindResource("areaCodesViewSource")));
        areaCodesViewSource.View.MoveCurrentToFirst();

        try
        {
            if (source.Text.Length >= 3 && destination2 != null)                                        //Info tab area code check
            {
                destination.Text = locationsDataSet.AreaCodes.FindByArea_Code(source.Text).Location.ToString();
                destination2.Text = locationsDataSet.AreaCodes.FindByArea_Code(source.Text).Time_Zone.ToString();
            }
            else if (source.Text.Length >= 3 && destination.Text.Length == 0 && destination2 == null)   //Other area code checks
            {
                destination.Text = locationsDataSet.AreaCodes.FindByArea_Code(source.Text).Location.ToString();
            }
            else if (source.Text.Length < 3 && destination2 != null)                                    //Info tab area code check
            {
                destination.Text = "";
                destination2.Text = "";
            }
            else if (source.Text.Length < 3 && destination.Text.Length == 0 && destination2 == null)    //Other area code checks
            {
                destination.Text = "";
                if (destination2 != null)
                {
                    destination2.Text = "";
                }
            }
        }
        catch (NullReferenceException)
        {
            destination.Text = "Invalid Area Code";
            if (destination2 != null)
            {
                destination2.Text = "";
            }
        }
    }
    #endregion
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:19:57+00:00Added an answer on June 4, 2026 at 11:19 am

    In playing around with this I actually found the answer on my own, actually a very simple fix that I should have noticed right away. When I copied the VS generated code, I copied the whole thing into the Locate methods, which were called by the OnTextChanged events, causing a new instance of each DB every time a character was entered in the textbox. Needless to say this was a massive memory drain.

    To fix it, I just moved the declarations for the DataSetvariables into the class level of the main window, and created a new InitializeDB() method called from MainWindow().

    Leaving this here (and answering it) just in case anybody else makes such a ridiculous error in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently trying at add ajax to a site, after much reading I discovered that
I know about $(Delphi) and $EDNAME but after much seaching I cant find a
I cannot find much documentation of the Boost version of discrete_distribution. After much Google
After much searching the answer seems to be no, but I thought I'd ask
It appears after much searching that there seems to be a common problem when
After much searching, I found the download for the eclipse version of jalopy .
After much searching and trials, I am stuck... I have two classes, one is
-Edit: Solution Found- Figured it out after some heavy searching - one person (I
I've been searching around trying to find an answer both here and google, although
After searching around for quite a while and trying to come up with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.