1

Ok, So i am trying to write a program for my HP Ipaq211 that I can use at work (I am a server) to take orders, as opposed to using paper. I have gotten pretty far and decided that it would be best to use a database to hold the full menu information. I created a database for drinks to start with 4 Columns {ID, Item, Price, Options} where ID is the primary Key.

I created a few concoctions that allow me to read the data into an object, and then create a list of those said objects, but all of them perform really slow (4 sec ish on the Ipaq). I have taught myself everything I know in terms of programming so bear with me, here is one of my attempts (which works but is slow and i need it to work faster!)

    public class _itemObject
    {

    public _itemObject()
    {

        ID = 0;
        _ioName = "";
        _ioPrice = "";
        _ioOptions = -1;

    }
        public _itemObject(int _next, string Tbl_Name)
        {
        try
        {

            string conSTR = "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) +
                    "\\TestDatabase.sdf;Persist Security Info=True";
            SqlCeConnection _connection = new SqlCeConnection(conSTR);


            SqlCeCommand _cmd = new SqlCeCommand("select ID from " + Tbl_Name + " where ID ='" + _next.ToString() + "'", _connection);
            SqlCeCommand _cmd2 = new SqlCeCommand("select * from " + Tbl_Name + " where ID ='" + _next.ToString() + "'", _connection);
            SqlCeCommand _cmd3 = new SqlCeCommand("select price from " + Tbl_Name + " where ID ='" + _next.ToString() + "'", _connection);
            SqlCeCommand _cmd4 = new SqlCeCommand("select special from " + Tbl_Name + " where ID ='" + _next.ToString() + "'", _connection);



            _connection.Open();
            if (_cmd.ExecuteScalar() != null)
            {

                ID = (Convert.ToInt32(_cmd.ExecuteScalar().ToString()));
                _ioName = _cmd2.ExecuteScalar().ToString();
                _ioPrice = _cmd3.ExecuteScalar().ToString();
                _ioOptions = (Convert.ToInt32(_cmd4.ExecuteScalar().ToString()));
            }
            else
            {

            }
            _connection.Close();
        }

        finally
        {

        }
        }

this object is then added to a List<_itemObject> where I load any needed data from.

I know it is ugly but if anyone has any lessons for me I would appreciate it :)

Michael
  • 75
  • 6
  • Not answering your question, but you may want to use SQL Express or LocalDB in place of SQL CE, as it is being deprecated. See http://stackoverflow.com/a/20364011/325521 for relevant microsoft MSDN links discussing this deprecation and alternatives. – Shiva Feb 07 '14 at 20:36
  • 1
    Thanks for the post, although It does not seem to apply to me (not saying there isnt a workaround so that it does). But I am forced to use Visual Studio 2008 and .NET Compact Framework 3.5 where all of the info on there is for Visual Studio 2010 and .NET 4... Stupid Windows Mobile 6.1!! and HP for not providing very good updates... – Michael Feb 08 '14 at 04:26

1 Answers1

1

The answer may differ on what is your final goal.

a) why do you need to use 4 sql commands? One command should be OK to get all information. In example:

SELECT * FROM table_name;

will report all data at once within a SqlCeDataReader.ExecuteReader() call that you can iterate to fill a list.

b) if no SQL server will be invoked later (for remote access/sync etc) and if not too much data records, you may consider switching to another data storage (ie xml (slow too) or binary file).

please provide more details if you need more help.

There are also SQLCE examples available here in stackoverflow: Local database, I need some examples and others (use search).

OK, from your comments I see you have some issues getting started?!

At http://www.codeproject.com/Articles/310378/A-Restaurant-and-Waiter-helper-app-in-WPF-and-Wind you will find a complete POS solution. You can change the waiter's code to use a local database.

...maybe adding some simple example later...

Community
  • 1
  • 1
josef
  • 5,951
  • 1
  • 13
  • 24
  • Well... I guess I could use 1 Sql command... like I said I have taught myself everything I know and the SQL commands confused me for a while, but I am getting better... i think... so the if I use `SqlCeDataReader.ExecuteReader()` how is the best way to iterate through the items... and I looked at the link, which will be very helpful I think so thanks!!! I am thinking that using a `DataTable` will help, you have any thoughts? as for part b) I can gladly give you tons of more info If you would like but I cannot fit it all in a single comment so but i'll post a followup comment in a sec. – Michael Feb 08 '14 at 07:51
  • ok, so I will be having (currently tell me if this is bad) 1 database with about 12 tables. Each table is going to be named something like "Beverages", or "Entrees" and contain the 4 columns mentioned in the original post. There will be a "Main Control" that houses buttons labeled "beverages", "entrees", etc... when the "beverages" button is clicked it will open a new form and populate button's text with the string from the Item column. then when the button "Water" is clicked i need to have the app know the remaining info that was in the row "Water" – Michael Feb 08 '14 at 07:56
  • oh, and since it is on a Handheld Device and I wont have an internet connection this database is a local one. – Michael Feb 08 '14 at 07:58
  • Well, I am way past started... haha put a lot of work into it o far but it is currently a jumbled mess because 99% of my code is trail and error... :( but the first link you gave me was potentially the crown jewel because I changed some of my code to reflect theirs a bit more and it (so far seems) to be MUCH faster... but Ill keep you updated... Also I checked the second link and I am going to download it and take a look maybe get some cool ideas, I cant believe I havent stumbled across it before! @josef – Michael Feb 08 '14 at 08:52
  • 1
    OK, some tipps: try to use classes and helpers/wrappers often, so you get independent modules you can easily re-write. For example: move all code to manage (retrive, change, etc) data into a class. Move data layer into a separate class, so you can switch from sqlCe to sqlite or whatever. As you have multiple tables with same struct, abstract that to get data classes that are based on the same class. You can then re-use the base class code without writing the same code again and again. – josef Feb 08 '14 at 09:12
  • hey, I am making amazing progress from your help so far. but I have reached another hiccup I cannot seem to figure out why, but I have a database that one of the columns is for a filepath and I cannot seem to load the string from the database and still have it reference the the file properly! any tips? :) – Michael Feb 12 '14 at 06:17
  • Please post a new question for this and provide code and details! – josef Feb 12 '14 at 07:28
  • I just wanted to post here to let you know that I finally had enough Reputation to upvote your answer, so thanks again! – Michael Apr 25 '14 at 08:06