[英]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? ...最适合我的情况-可滚动?
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.