点击Raspberry Pi触摸屏按钮将数据发送到数据库

时间:2018-01-31 07:55:42

标签: sqlite raspberry-pi3 touchscreen windows-iot-core-10

我正在使用网站上的代码(https://www.hackster.io/dotMorten/windowsiottouch-44af19)  显示我的触摸屏。

我试过的每个sqlite代码都不起作用。 我甚至无法使用引用:'using microsoft.data'

我无法将我的UWP连接到数据库。我遵循了许多教程并尝试了nuget包,但它不起作用。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Data;
using TouchPanels.Devices;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Automation.Provider;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using SQLite;
using SQLitePCL;



// The Blank Page item template is documented at 
http://go.microsoft.com/fwlink/?LinkId=234238

namespace WindowsIoT.TouchSample
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a 
Frame.
/// </summary>
/// 
public sealed partial class ManualUnlock : Page
{
    //Please help change the database constring
    // string connStr = @"Server=myServerName\myInstanceName;" +"Initial 
       Catalog=myDataBase;Integrated Security=True;";
    //SqlConnection conn = new SqlConnection(connStr);
    //conn.Open();
    private SQLiteConnection sql_con;
    private SQLiteCommand sql_cmd;


    const string CalibrationFilename = "TSC2046";
    private Tsc2046 tsc2046;
    private TouchPanels.TouchProcessor processor;
    private Point lastPosition = new Point(double.NaN, double.NaN);
    public ManualUnlock()
    {
        this.InitializeComponent();
    }

    private void page_loaded(object sender, RoutedEventArgs e)
{

        //write logic here
        string tempcode = NumGen();
        txtOTP.Text = tempcode;

        Stopwatch timer = new Stopwatch();
        timer.Start();
        while (timer.Elapsed.TotalSeconds < 120)
        {
            using (sql_con)
            {
                // create a new database connection:
                SQLiteConnection sqlite_conn =
                  new SQLiteConnection("Data Source=App_Data/Simplicity.mdf;");
                // open the connection:
       ******************  sqlite_conn.Open();  
                sqlite_cmd = sqlite_conn.CreateCommand();
                sqlite_cmd.CommandText = "SELECT * FROM account WHERE OTP =@otp";
                // The SQLiteDataReader allows us to run through each row per loop
                while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
                {
                    // Print out the content of the text field:


                    /*Sends message to database saying authenticated*/

                }
            }
        }
        timer.Stop();
    }

星号线上“打开”的红线虽然我有参考

1 个答案:

答案 0 :(得分:0)

SQLite是一个嵌入式SQL数据库引擎。与大多数其他SQL数据库不同,SQLite没有单独的服务器进程。 SQLite直接读写普通磁盘文件。从您提供的代码

  

SQLiteConnection sqlite_conn = new SQLiteConnection(“Data Source = App_Data / Simplicity.mdf;”);

似乎数据库不是SQLite而是SQL Server数据库文件。您可以参考此sample关于Windows 10 UWP中的Sqlite支持,或者您可以参考此guide来说明如何使用SQLite在您设备上的轻量级数据库中存储和检索数据。