【发布时间】:2010-01-07 07:18:18
【问题描述】:
当我在我的移动应用程序中运行此 SQl 时,我得到零行。
select * from inventory WHERE [ITEMNUM] LIKE 'PUMP%' AND [LOCATION] = 'GARAGE'
当我在查询分析器 3.5 中使用相同的数据库运行相同的 SQL 时,我得到了预期的一行。
为什么不一样?
这是我在移动应用中使用的代码:
SqlCeCommand cmd = new SqlCeCommand(Query);
cmd.Connection = new SqlCeConnection("Data Source="+filePath+";Persist Security Info=False;");
DataTable tmpTable = new DataTable();
cmd.Connection.Open();
SqlCeDataReader tmpRdr = cmd.ExecuteReader();
if (tmpRdr.Read())
tmpTable.Load(tmpRdr);
tmpRdr.Close();
cmd.Connection.Close();
return tmpTable;
更新: 为了尝试,我使用了在here 找到的答案之一中找到的代码,它按预期工作。所以我的代码如下所示:
SqlCeConnection conn = new SqlCeConnection("Data Source=" + filePath + ";Persist Security Info=False;");
DataTable tmpTable = new DataTable();
SqlCeDataAdapter AD = new SqlCeDataAdapter(Query, conn);
AD.Fill(tmpTable);
问题似乎与 SqlCeDataReader 有关。
希望这对其他人有所帮助!
【问题讨论】:
标签: .net sql compact-framework sql-server-ce