locked
Best way to load items : On Text Changed OR dump RRS feed

  • Question

  • Hi All, 

    I have an application where user will be purchasing items continuously.

    So, while purchasing he wants the recent details of the products he is purchasing.

    What i did, select * form invoicemaster then dump this into Purchase form and search within it whenever whatever he wants.

    As of now its running well. Cause there are around 5000 items.

    But when in near by future it will go to 1 Lakh plus records ?????????? OMG i can not even imagine.

    Please suggest me better way to handle this question.

    Also, while selling items i just collect the items from DB where remaining items>0 and dump. SO he can search any item he want to sell through that dumped data. But what will happen if this count goes to 1 lakh records??????

    Please suggest me better way....

    Sunday, December 22, 2019 6:01 PM

Answers

  • Hi NirajZ,

    It seems that your problem has been solved. If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by NirajZ Wednesday, December 25, 2019 5:30 AM
    Wednesday, December 25, 2019 5:26 AM

All replies

  • I hope customer doesn't want to draw all items in screen :) You can create some paging or lazy loading when customer scroll down then load next items.
    Sunday, December 22, 2019 7:24 PM
  • Hello,

    A preferred method is to provide a screen which allows the user to search/filter then return relevant records. Otherwise you will need to look at (thinking a DataGridView) virtual mode or pagination yet this in turn does not fully resolve your issue and in the end will end up with a ton of code.

    Going back to a search screen, dependent on the database design somethings can be presented in a ComboBox or ListBox for reference tables e.g. let's say projects are broken down into categories, provide a ComboBox or ListBox with category names and a "show all" that would work in tangent with other filters.

    For things like product name, provide a TextBox and radio buttons where the user can enter text and the radio buttons allow "starts with", "contains (like), "ends with", exact match (case sensitive or case insensitive). Don't try and get fancy (build controls dynamically) if you never have done this before, keep it simple.

    If even a filter/search might bring back a large amount of records consider using async operations e.g. something I had open, populate a reference table into a list. Note that this is basic and may need more (most likely). Consider providing the ability to cancel loading data and if that is the case you need to learn about working with these types of operations as one does not simply grab code samples off the web and try it out. A good base is here.

    public async Task<List<ContactType>> LoadContactTypes()
    {
        mHasException = false;
    
        var contactList = new List<ContactType>();
    
        using (var cn = new SqlConnection() { ConnectionString = ConnectionString })
        {
            using (var cmd = new SqlCommand() { Connection = cn })
            {
                cmd.CommandText = "SELECT ContactTypeIdentifier,ContactTitle  FROM dbo.ContactType";
                try
                {
    
                    /*
                     * If there is an issue with the connection using
                     * Open will freeze the user interface
                     */
                    await cn.OpenAsync();
    
                    var reader = await cmd.ExecuteReaderAsync();
    
                    while (await reader.ReadAsync())
                    {
                        contactList.Add(new ContactType()
                        {
                            ContactTypeIdentifier = await reader.GetFieldValueAsync<int>(0),
                            ContactTitle = await reader.GetFieldValueAsync<string>(1)
                        });
    
                    }
                }
                catch (Exception ex)
                {
                    mHasException = true;
                    mLastException = ex;
                }
            }
        }
    
    
        return contactList;
    
    }
    In closing, don't try and load extremely large sets of data as this is inherently going to cause undue issues were reading the database is better.  


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, December 22, 2019 7:42 PM
  • What i did, select * form invoicemaster then dump this into Purchase form and search within it whenever whatever he wants.

    1) You don't do a Select * with a T-SQL from a table

    https://dzone.com/articles/why-you-should-not-use-select-in-sql-query-1

    2) You search for records based on the filtering criteria at the database level and not with a control's data  at the UI.

    But when in near by future it will go to 1 Lakh plus records ?????????? OMG i can not even imagine.

    You can implement paging at the database level or the control at the UI can have paging implemented.

    Sunday, December 22, 2019 7:51 PM
  • So, finally came with a solution.

    1. Just get the list of products with DISTINCT from inventory.

    2. On cellvaluechangedevent get the item details so it means i dont have to dump the data on the form.

    So, performance has been tremendously improved. 

    Thanks all.

    Tuesday, December 24, 2019 5:19 PM
  • Hi NirajZ,

    It seems that your problem has been solved. If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by NirajZ Wednesday, December 25, 2019 5:30 AM
    Wednesday, December 25, 2019 5:26 AM