Search code examples
sqliteraspberry-pi3touchscreenwindows-iot-core-10

Raspberry Pi touch screen button on click sends data to database


I am using the codes from the site (https://www.hackster.io/dotMorten/windowsiottouch-44af19) to display my touchscreen.

Every sqlite code i tried doesnt work. I cant even use reference :'using microsoft.data'

I cant connect my UWP to database.I followed many tutorials and tried the nuget package also but it doesnt work.

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();
    }

red lines from "open" on asterisk line although i have reference


Solution

  • SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files.From the code you provided,

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

    It seems that the database is not SQLite but SQL Server database file.You can refer to this sample about Sqlite support in Windows 10 UWP, or you can refer to this guide that shows how to use SQLite to store and retrieve data in a light-weight database on the your device.