我正在使用 SQL CE 4.0 和以下代码:
string sqlQuery = "SELECT TOP 10 " +
"tbl_Image.ImageID, tbl_Barcode.BarcodeValue, tbl_Image.ImageDateTime, tbl_Image.ImageFileName " +
"FROM " +
"tbl_Image " +
"JOIN tbl_Barcode on tbl_Image.ImageID = tbl_Barcode.ImageID " +
"WHERE " +
"tbl_Image.ImageID > @ImageID";
using (SqlCeCommand command = new SqlCeCommand(sqlQuery, sqlceServer.GetSqlConnection()))
{
command.Parameters.Add(new SqlCeParameter("@ImageID", SqlDbType.Int)).Value = imageID;
try
{
using (SqlCeDataReader rdr = command.ExecuteResultSet(ResultSetOptions.Scrollable))
{
if (rdr.HasRows)
{
while (rdr.Read())
{
但我不断收到错误:
“在当前范围内找不到与所述特征匹配的密钥”
在这条线上:
using (SqlCeDataReader rdr = command.ExecuteResultSet(ResultSetOptions.Scrollable))
我曾尝试将此行更改为各种不同的选项,但无济于事。
我的 sql ce db 包含使用以下(摘录)创建的两个表:
string tblImage =
"CREATE TABLE [tbl_Image] (" +
"[ImageID] int IDENTITY (1,1) NOT NULL" +
", [ImageData] image NOT NULL" +
", [ImageDateTime] datetime NOT NULL" +
", [ImageFileName] nvarchar(4000) NOT NULL" +
", [SettingID] int NOT NULL" +
", [MultiPage] bit NOT NULL" +
");";
string tblBarcode =
"CREATE TABLE [tbl_Barcode] (" +
"[BarcodeID] int IDENTITY (1,1) NOT NULL" +
", [ImageID] int NOT NULL" +
", [BarcodeType] nvarchar(4000) NOT NULL" +
", [BarcodeValue] nvarchar(4000) NOT NULL" +
");";
string alterImageTable =
"ALTER TABLE [tbl_Image] ADD CONSTRAINT [PK_tbl_Image] PRIMARY KEY ([ImageID]);";
string alterBarcodeTable =
"ALTER TABLE [tbl_Barcode] ADD CONSTRAINT [PK_tbl_Barcode] PRIMARY KEY ([BarcodeID]);";
我对问题所在感到困惑——谷歌搜索错误似乎是指我没有做的复制问题。有人可以帮忙吗?
编辑:
在 SQL Server Compact Toolbox v4.0 中运行查询没有问题并返回正确的数据。