c# - SQLite 数据库游标始终返回 0,即使表已正确填充
问题描述
我已将数据保存在表 PollCollection(PollID, PollName, VotingClass) 和 OptionCollection(OptionID, PollID, Option) 中。我有一个名为 Poll 的类,其中可以保存字符串 PollTitle 和 LinkedList 选项(以及其他选项)。我使用适当的 VotingClass 从 PollCollection 中读取了我的第一个 PollName,然后尝试从其中 PollID = PollCollection.PollID 的 OptionCollection 中读取 Option。但是,我的选项光标的长度为 0。
我知道 OptionCollection 已正确保存的事实,因为在另一段代码中,我设法运行了 select * 查询并打印了所有适当的值。在这一点上,我不知道我错过了什么。另外,我正在使用 Xamarin Android。
string pollquery = "";
string optionsquery = "";
pollquery = string.Format("select * from PollCollection where PollCollection.VotingClass = '{0}'", userclass);
ICursor polls = MainActivity.sqlitedb.RawQuery(pollquery, null);
if (polls.Count > 0)
{
polls.MoveToFirst();
do
{
Poll currentpoll = new Poll();
currentpoll.PollTitle = polls.GetString(polls.GetColumnIndex("PollName"));
string pollid = polls.GetString(polls.GetColumnIndex("PollID"));
optionsquery = string.Format("select Option from OptionCollection where OptionCollection.PollID = '{0}'", pollid);
ICursor options = MainActivity.sqlitedb.RawQuery(optionsquery, new string[] { });
options.MoveToFirst();
do
{
currentpoll.Options.AddLast(options.GetString(options.GetColumnIndex("Option")));
} while(options.MoveToNext());
polllist.AddLast(currentpoll);
} while (polls.MoveToNext());
}
解决方案
推荐阅读
- java - 尝试使用 SharedPreferences 从 AmbilWarnaDialog 保存颜色,但没有获得颜色
- python - 如何不在最后一个元素后添加分隔符
- jmeter - Jmeter-将运行时数据写入 csv(column) 文件
- c# - 每个表中的列名必须是唯一的例外
- c# - dgv 为 DataBinding 时 WinForms 中 DataGridView 的排序问题
- cassandra - 仅登录并“查看”特定键空间/表的 Cassandra 角色/用户
- symfony - 如何使用否定条件过滤带有查询生成器的相关实体?
- javascript - 为 JavaScript 函数调用增加值的正确方法
- python - 无法将记录插入表中 提供的绑定数量不正确
- python - RabbitMQ 持久队列绑定