[英]C# .net 3.5 Compact SqlCe
好的,所以我想為我的HP Ipaq211編寫一個程序,該程序可以在工作中(我是服務器)用來接單,而不是用紙。 我已經走了很遠,並決定最好使用數據庫保存完整的菜單信息。 我創建了一個飲料數據庫,以4列{ID,Item,Price,Options}開頭,其中ID是主鍵。
我創建了一些混合函數,使我可以將數據讀取到一個對象中,然后創建這些對象的列表,但是所有這些對象的執行速度都非常慢(在Ipaq上為4秒)。 我已經學會了編程方面的所有知識,所以請多多包涵,這是我的嘗試之一(有效但很慢,我需要使其更快地工作!)
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
{
}
}
然后將該對象添加到List<_itemObject>
, List<_itemObject>
加載任何需要的數據。
我知道這很丑陋,但是如果有人對我有什么教訓,我將不勝感激:)
最終目標是什么,答案可能會有所不同。
a)為什么需要使用4個sql命令? 一個命令應該可以獲取所有信息。 例如:
SELECT * FROM table_name;
將在SqlCeDataReader.ExecuteReader()調用中一次報告所有數據,您可以迭代以填充列表。
b)如果以后沒有調用SQL Server(用於遠程訪問/同步等),並且如果數據記錄不太多,則可以考慮切換到另一個數據存儲(即xml(太慢)或二進制文件)。
如果您需要更多幫助,請提供更多詳細信息。
在stackoverflow中,還有SQLCE示例可用: 本地數據庫,我需要一些示例和其他示例 (使用搜索)。
好吧,從您的評論中我看到您有一些入門方面的問題?!
在http://www.codeproject.com/Articles/310378/A-Restaurant-and-Waiter-helper-app-in-WPF-and-Wind中,您將找到完整的POS解決方案。 您可以將服務員的代碼更改為使用本地數據庫。
...也許以后再添加一些簡單的示例...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.