简体   繁体   English

如何将TableDirect用于SQL Server CE?

[英]How can I use TableDirect for SQL Server CE?

I have code that works for querying data from a SQL Server CE table and populating a generic list with it. 我有一些代码可用于从SQL Server CE表查询数据并用它填充通用列表。 That can be seen here : 可以在这里看到:

But a comment there indicates I should trade in my horse-and-buggy for a Leer Jet; 但是那里的评论表明我应该用马车换购Leer Jet。 so, I'm trying to adapt code I found here and have this so far: 所以,我正在尝试改编我在这里找到的代码并且到目前为止:

public static List<HHSUtils.InventoryItem> SelectLocalInventoryItemsTableDirect()
{
    var invItems = new List<HHSUtils.InventoryItem>();
    using (var conn = new SqlCeConnection(dataSource))
    {
        conn.Open();
        SqlCeCommand cmd = conn.CreateCommand();
        cmd.CommandType = CommandType.TableDirect;
        cmd.CommandText = "InventoryItems";
        using (SqlCeResultSet rs cmd.ExecuteResultSet(ResultSetOptions.Scrollable))
        {
            cmd.Prepare();
            while (rs.Read())
            {
                var invItem = new HHSUtils.InventoryItem
                {
                    Id = Convert.ToString(rs["Id"]),
                    PackSize = Convert.ToInt16(rs["PackSize"]),
                    Description = Convert.ToString(rs["Description"]),
                    DeptDotSubdept = Convert.ToDouble(rs["DeptDotSubdept"]),
                    Unit_Cost = Convert.ToDouble(rs["UnitCost"]),
                    Unit_List = Convert.ToDouble(rs["UnitList"]),
                    UPC_code = Convert.ToString(rs["UPCCode"]),
                    UPC_pack_size = Convert.ToInt16(rs["UPCPackSize"]),
                    CRV_Id = Convert.ToInt32(rs["CRVId"])
                };
                invItems.Add(invItem);
            }
        }
    }
    return invItems;
}

...but since I'm simply looping through the result set to populate the generic list, I reckon I don't want ResultSetOptions.Updatable (and I'll need different code following that). ...但是由于我只是循环遍历结果集以填充通用列表,因此我认为我不希望ResultSetOptions.Updatable(并且在此之后我需要其他代码)。 Of the following possibilities: 有以下几种可能性:

Insensitive
None
Scrollable
Sensitive
Updatable

...which is best for my situation - Scrollable? ...最适合我的情况-可滚动?

UPDATE UPDATE

This seems to work fine, and fast, but I still don't know which ResultSetOptions property is optimal... This msdn article talks about this enumeration, but doesn't exactly go into great depth about when they should/not be used. 这似乎工作正常,而且很快,但是我仍然不知道哪个ResultSetOptions属性是最佳的。 此msdn文章讨论了此枚举,但是对于何时/不应该使用它们并没有深入探讨。

You'd want to use None in your case. 您想在情况下使用None cmd.Prepare is also unnecessary. cmd.Prepare也没有必要。 As indicated in this question , GetValues is also faster. 该问题所示 ,GetValues也更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将SQL Server CE用于我的ASP.net MVC成员/授权项目? - How can I use SQL Server CE for my ASP.net MVC membership/authorization project? 如何在SQL ce中使用max(id)作为搜索条件? - How can i use max(id) as a search condition in sql ce? 如何使用Sql CE 4数据库进行功能测试 - How can I use Sql CE 4 databases for functional tests EF7和SQLite麻烦大了,我可以在Mobile中使用SQL Server CE吗? - EF7 and SQLite big troubles, can I use SQL Server CE with Mobile? 在VS2012中无法使用SQL Server CE - Can't use SQL Server CE in VS2012 当一个是SQL Server CE时,如何将TransactionScope与两个数据库一起使用? - How do I use a TransactionScope with two databases when one is SQL Server CE? 如何检查 SQL Server CE 3.5 中是否存在表 - How can I check whether a table exists in SQL Server CE 3.5 如何在SQL Server CE数据库上出现“ 80004005文件共享冲突…”错误消息? - How can I circument the “80004005 There is a file sharing violation…” err msg on a SQL Server CE database? 如何使我的SQL Server CE连接打开得更快? - How can I make my SQL Server CE connection open faster? 如何为SQL Server CE使用动态连接字符串? - How to use dynamic connection string for SQL Server CE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM