在 SQL Server CE 中将 SqlCEResultSet.Seek 与复合键结合使用
有人可以告诉我如何将 SqlCeResultSet.Seek
方法与复合索引一起使用吗?
我正在尝试寻找 orderno+product code
。
我的 SQL Server CE 表具有以下索引:
CREATE INDEX orderline_idx ON OrderLines (orderno, item)
我的查找代码是
public bool SeekDeliveryLine(string delnote,string item)
{
bool isFound = false;
cmd = new SqlCeCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.TableDirect;
cmd.CommandText = "OrderLines";
cmd.IndexName = "orderline_idx ";
try
{
//cmd.SetRange(DbRangeOptions.Match, new object[] { delnote }, null);
deliveryRS = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
isFound = deliveryRS.Seek(DbSeekOptions.FirstEqual, new object[] { delnote, item });
if (isFound)
{
deliveryRS.Read();
currentRowData = this.RetrieveRecord();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return isFound;
}
该代码始终返回第一个匹配的订单行。
预先感谢
保罗
Can someone show me how I can use the SqlCeResultSet.Seek
method with a composite index?
I am trying to seek on orderno+product code
.
My SQL Server CE table has the following index:
CREATE INDEX orderline_idx ON OrderLines (orderno, item)
My seek code is
public bool SeekDeliveryLine(string delnote,string item)
{
bool isFound = false;
cmd = new SqlCeCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.TableDirect;
cmd.CommandText = "OrderLines";
cmd.IndexName = "orderline_idx ";
try
{
//cmd.SetRange(DbRangeOptions.Match, new object[] { delnote }, null);
deliveryRS = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
isFound = deliveryRS.Seek(DbSeekOptions.FirstEqual, new object[] { delnote, item });
if (isFound)
{
deliveryRS.Read();
currentRowData = this.RetrieveRecord();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return isFound;
}
The code always returns the first matching order line.
Thanks in advance
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查找输入数据数组必须是等于索引字段的对象。您无法查找不在索引中的字段。看起来您在订单号和项目上有一个索引,我认为它是一个整数和一个字符串,但您传递的是“delnote”和项目,它们都是字符串。
The seek input data array must be objects that equate to the indexed fields. You cannot seeok on a field that is not in the index. It looks like you have an index on the order number and item, which I'd think is an int and a string, but you're passing in "delnote" and item, which are both strings.
感谢您的回答,这两个字段都是字符串。我正在导入一个将订单号存储为字符串的后端。 delnote 字段的命名很糟糕(我最初正在处理送货单编号,但尚未重构变量名称)。我现在已经让这段代码正常工作了,我将其重写如下,我不确定为什么将字符串存储到对象中应该会产生任何影响,但它现在正在工作。
OT警告:SDF2.3与vs2010兼容吗?我们即将升级。
Thanks for your answer, both fields are strings. I am importing into a backend that stores the order number as a string. The delnote field is just poorly named (I was working on delivery note numbers originally and hadn't refactored the variable name yet). I have now got this code working I re-wrote it as below, I'm not sure why storing the strings into object should make any difference but it is now working.
OT Warning: is SDF2.3 compatable with vs2010? we are upgrading soon.