Uwp 如何从listview中所选项目的数据库中获取id
我正在尝试从已单击项目的数据库中获取id。要在列表视图中获取已单击项的id,必须执行的操作。它将零显示为值,以及如何根据该id从数据库中获取描述Uwp 如何从listview中所选项目的数据库中获取id,uwp,Uwp,我正在尝试从已单击项目的数据库中获取id。要在列表视图中获取已单击项的id,必须执行的操作。它将零显示为值,以及如何根据该id从数据库中获取描述 namespace javalearningapp_v1 { public sealed partial class tutorial: Page { string path; SQLite.Net.SQLiteConnection conn; private List < tutorial
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);
}
}
}
名称空间javalearningapp\u v1{
公共密封部分类教程:第页{
字符串路径;
SQLite.Net.SQLite连接连接;
私有列表listOfStudents=新列表();
公共教程(){
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();
检索();
}
公共类教程数据库{
[主密钥]
公共Int32 sno{
得到;
设置
}
公共字符串名称{
得到;
设置
}
公共字符串描述{
得到;
设置
}
}
私有void检索(){
var query=conn.Table();
字符串名称=”;
foreach(查询中的var消息){
name=message.lname;
添加(新教程数据库){
lname=名称
});
}
tutorialist.ItemsSource=学生列表;
}
private void tutoriallist\u ItemClick(对象发送者,ItemClickEventArgs e){
tutorialistdb项=(tutorialistdb)e.单击编辑项;
var desc=conn.Query(“从tutorialistdb中选择描述,其中sno=?”,a.sno);
帧导航(typeof(tutdesc),desc);
}
}
}
var desc=conn.QuerySql
语句,我建议您传递一个字符串类型参数
用法
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);
}
未指定tutoriallist
中此项目的sno属性。它是
总是零。因此,如果sno
为零,则只能查询一个相同的数据
修改
foreach (var message in query)
{
name = message.lname;
listOfStudents.Add(new tutoriallistdb { lname = name , sno = message.sno });
}
tutoriallist.ItemsSource = listOfStudents;
foreach (var message in query)
{
name = message.lname;
listOfStudents.Add(new tutoriallistdb { lname = name , sno = message.sno });
}
tutoriallist.ItemsSource = listOfStudents;