我正在尝试遍历 SQLite 查询,并且对于找到的每个 pk,我都想获取 column 的相应值date
。这是我到目前为止所拥有的。我的 dynamictextbox1 充满了代码而不是日期。
public void createEntry()
{
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db");
/*using (var db = new SQLiteConnection(dbPath))
{
db.CreateTable<LogEntry>();
db.RunInTransaction(() =>
{
db.Insert(new LogEntry() { date = dateBox.SelectedItem.ToString(),
startTime = startTimeBox.SelectedItem.ToString(),
endTime = endTimeBox.SelectedItem.ToString(),
activity = activityBox.SelectedItem.ToString(),
type = typeBox.SelectedItem.ToString()
});
});
}*/
//If the database is empty then don't set the listview itemssource to it otherwise you will get an error.
using (var db = new SQLiteConnection(dbPath))
{
if (db.Table<LogEntry>().Count() > 0)
{
var query0 = db.Table<LogEntry>().Select(v => v.ID);
var query1 = db.Table<LogEntry>().Select(v => v.date.ToString());
var query2 = db.Table<LogEntry>().Select(v => v.startTime.ToString());
var query3 = db.Table<LogEntry>().Select(v => v.endTime.ToString());
var query4 = db.Table<LogEntry>().Select(v => v.activity.ToString());
var query5 = db.Table<LogEntry>().Select(v => v.type.ToString());
foreach (var item0 in query0)
{
//var dateID = db.Table<LogEntry>().Where(v => v.ID = query0);
//Create the controls and populate them.
StackPanel dynamicStackPanel0 = new StackPanel();
dynamicStackPanel0.Orientation = Orientation.Horizontal;
StackPanel dynamicStackPanel1 = new StackPanel();
StackPanel dynamicStackPanel2 = new StackPanel();
StackPanel dynamicStackPanel3 = new StackPanel();
TextBlock dynamicTextBlock1 = new TextBlock();
var dataID = db.Table<LogEntry>().Where( v => v.ID.Equals(item0)).Select(v => v.date);
dynamicTextBlock1.Text = dataID.ToString();
TextBlock dynamicTextBlock2 = new TextBlock();
foreach (var item2 in query2)
{
dynamicTextBlock2.Text = item2.ToString();
}
TextBlock dynamicTextBlock3 = new TextBlock();
foreach (var item3 in query3)
{
dynamicTextBlock3.Text = item3.ToString();
}
TextBlock dynamicTextBlock4 = new TextBlock();
foreach (var item4 in query4)
{
dynamicTextBlock4.Text = item4.ToString();
}
TextBlock dynamicTextBlock5 = new TextBlock();
foreach (var item5 in query5)
{
dynamicTextBlock5.Text = item5.ToString();
}
TextBlock dynamicTextBlock6 = new TextBlock();
dynamicTextBlock6.Text = "Rating 1";
TextBlock dynamicTextBlock7 = new TextBlock();
dynamicTextBlock7.Text = "Rating 2";
TextBlock dynamicTextBlock8 = new TextBlock();
dynamicTextBlock8.Text = "Rating 3";
//Create the entries.
dynamicStackPanel1.Children.Add(dynamicTextBlock1);
dynamicStackPanel1.Children.Add(dynamicTextBlock2);
dynamicStackPanel1.Children.Add(dynamicTextBlock3);
dynamicStackPanel2.Children.Add(dynamicTextBlock4);
dynamicStackPanel2.Children.Add(dynamicTextBlock5);
dynamicStackPanel3.Children.Add(dynamicTextBlock6);
dynamicStackPanel3.Children.Add(dynamicTextBlock7);
dynamicStackPanel3.Children.Add(dynamicTextBlock8);
dynamicStackPanel0.Children.Add(dynamicStackPanel1);
dynamicStackPanel0.Children.Add(dynamicStackPanel2);
dynamicStackPanel0.Children.Add(dynamicStackPanel3);
entryPanel.Items.Add(dynamicStackPanel0);
}
}
}
}