如何使用SQLite保存在数据库中的值? [英] How to save values in database using Sqlite?

查看:149
本文介绍了如何使用SQLite保存在数据库中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的WP8跟踪器的应用程序。我要保存使用SQLite数据库中的值。所有值R工作组(时间,距离和速度)。经过pressing停止按钮,我需要的值被张贴在表视图中使用SQLite作为ü可以在第二个屏幕上看到。什么好的建议或链接是AP preciated。感谢ü。

I am trying to do a tracker application in wp8. I want to save the values in database using Sqlite. All the values r working (time, distance and pace). After pressing Stop button, I want the values to be posted in a table view using Sqlite as u can see in the second screen. Any good suggestions or links are appreciated. Thank u.

推荐答案

我假设你的表。

    public class HistoryTable
    {
        public string date { get; set; }
        public string time { get; set; }
        public double pace { get; set; }
        public double distance { get; set; }
    }

使用此语句插入值。

Insert values using this statement.

    string date = DateTime.Now.ToShortDateString();
    string time = DateTime.Now.ToShortTimeString();
    double pace = 16;
    double distance = 4;
    SQLiteConnection conn = new SQLiteConnection(System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Database.sqlite"));
    conn.Execute("Insert into HistoryTable values(?,?,?,?)", date, time, pace, distance);

取数据如下声明,我假设你知道如何在的如果有需要的列表框。我走在文本框中的值。

Fetch your data as below statement, I'm assuming that you know how to bind the data in listbox if there is need. I'm taking the values in textbox.

    SQLiteConnection conn = new SQLiteConnection(System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Database.sqlite"));
    var result = conn.Table<HistoryTable>();
    foreach (var val in result)
    {
        TimeSpan pace = TimeSpan.FromMinutes(val.pace);
        TextBoxDate.Text = val.date;
        TextBoxTime.Text = val.time;
        TextBoxPace.Text = pace.Minutes + ":" + pace.Seconds;
        TextBoxDistance.Text = val.distance + " Km";
    }

为什么我用步伐,双,因为我可以用这双价值共分钟,可以改变的时间跨度(以分和秒)。如有其它疑问,您可以问任何时间。 要获得完全一样的格式,你问你的问题,你应该使用这样也。

The reason why I used Pace as double because I can use this double value as total minutes and can be changed as timespan(in minutes and seconds). For any other queries you can ask any time. To get exactly the same format as you ask in your question you should use like this also.

    string date = string.Format("{0:00}.{1:00}.{2:00}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
    string time = DateTime.Now.ToString("HH:mm:ss");
    double pace = 16.5;
    double distance = 4;
    SQLiteConnection conn = new SQLiteConnection(System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Database.sqlite"));
    conn.Execute("Insert into HistoryTable values(?,?,?,?)", date, time, pace, distance);

目前的抓取信息时,请通过此更改上述步骤。

At the time of fetching info, please change the above steps by this.

    TextBoxDistance.Text = string.Format("{0:0.00}Km", val.distance);

这篇关于如何使用SQLite保存在数据库中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆