我正在尝试从所点击的项目的数据库中获取id。我需要做什么来获取列表视图中单击项的ID。它显示为零值以及如何根据数据库中的id获取描述。
namespace javalearningapp_v1 {
public sealed partial class tutorial: Page {
string path;
SQLite.Net.SQLiteConnection conn;
private List < tutoriallistdb > listOfStudents = new List < tutoriallistdb > ();
public tutorial() {
this.InitializeComponent();
path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "java2db.sqlite");
conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);
conn.CreateTable < tutoriallistdb > ();
Retrieve();
}
public class tutoriallistdb {
[PrimaryKey]
public Int32 sno {
get;
set;
}
public string lname {
get;
set;
}
public string description {
get;
set;
}
}
private void Retrieve() {
var query = conn.Table < tutoriallistdb > ();
string name = "";
foreach(var message in query) {
name = message.lname;
listOfStudents.Add(new tutoriallistdb {
lname = name
});
}
tutoriallist.ItemsSource = listOfStudents;
}
private void tutoriallist_ItemClick(object sender, ItemClickEventArgs e) {
tutoriallistdb item = (tutoriallistdb) e.ClickedItem;
var desc = conn.Query < tutoriallistdb > ("select description from tutoriallistdb where sno=?", a.sno);
Frame.Navigate(typeof(tutdesc), desc);
}
}
}
答案 0 :(得分:0)
var desc = conn.Query&lt; tutoriallistdb&gt; (&#34;从tutoriallistdb中选择说明,其中sno =?&#34;,a.sno);
问题似乎与您传递的参数类型有关。对于Sql
句子,我建议你传递字符串类型参数。
<强>用法强>
private void tutoriallist_ItemClick(object sender, ItemClickEventArgs e)
{
tutoriallistdb item = (tutoriallistdb)e.ClickedItem;
var desc = conn.Query<tutoriallistdb>("select description from tutoriallistdb where sno=?", item.sno.ToString());
Frame.Navigate(typeof(tutdesc), desc);
}
<强> PS 强> 我在代码中发现了错误的逻辑。
foreach (var message in query)
{
name = message.lname;
listOfStudents.Add(new tutoriallistdb { lname = name});
}
tutoriallist.ItemsSource = listOfStudents;
未分配tutoriallist
中此项目的sno属性。它是
总是零。因此,您只能查询sno
为零的同一数据。
修改
foreach (var message in query)
{
name = message.lname;
listOfStudents.Add(new tutoriallistdb { lname = name , sno = message.sno });
}
tutoriallist.ItemsSource = listOfStudents;