locked
SQLite Query Results to Entry Boxes RRS feed

  • Question

  • User386302 posted

    Hello,

    I am working on a project which requires me to query my database from the title that was tapped in the picker and then pull the full name, username and date to their respective entry boxes.

    Example:

    Picker on top of entry boxes displays titles, user picks one

    Entry boxes below :

    Title: Title goes here Full Name: Full name goes here Username: Username goes here Date and Time Date goes here

    The data is successfully being inserted to the database so this is the only part where I am stuck.

    Any help would be great!

    Thank you,

    Moose!

    Monday, June 3, 2019 4:27 PM

Answers

  • User386302 posted

    Hey Everyone,

    I found a solution works like a charm, see below!

            try
            {
                string entrydb = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), 
               "Entry.db");
                var db = new SQLiteConnection(entrydb);
    
    
                var getdata= db.Query<CreatedEntry>("SELECT Password FROM CreatedEntry WHERE (Title='" + 
                TitleViewList.SelectedItem + "')");
                foreach (var s in getdata)
                {
                    DisplayAlert("success", s.Password, "ok");
                }
    
            }
            catch
            {
    
            }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 5, 2019 2:06 AM

All replies

  • User2148 posted

    Binding

    Monday, June 3, 2019 5:08 PM
  • User386302 posted

    Do you have any references that show some examples?

    Monday, June 3, 2019 5:12 PM
  • User2148 posted

    https://docs.microsoft.com/it-it/xamarin/xamarin-forms/app-fundamentals/data-binding/

    Monday, June 3, 2019 5:51 PM
  • User386302 posted

    So I get that I have to bind the data but how do I get it from my db to bind it?

    Is there something in Xamarin C# like this, please see below?

            if(reportsCombo.Enabled == true)
            {
                getconnectionstring();
                // string connetionString = null;
                SqlConnection connection;
                SqlCommand command;
                string sql = null;
                SqlDataReader dataReader;
    
                sql = "SELECT     Title, Investigator, UserAssociated, IRDate, IncidentNum, Description, Summary, 
                Analysis,Conclusion,  ID FROM            IR_Template WHERE (Title='" + reportsCombo.Text + "')";
                connection = new SqlConnection(connetionString);
                try
                {
                    connection.Open();
                    command = new SqlCommand(sql, connection);
                    dataReader = command.ExecuteReader();
                    while (dataReader.Read())
                    {
                        // MessageBox.Show(dataReader.GetValue(0) + " - " + dataReader.GetValue(1)) ;// + " - " + 
                        dataReader.GetValue(2));
                        titleTXT.Text = dataReader.GetValue(0).ToString();
                        InvestigatorTXT.Text = dataReader.GetValue(1).ToString();
                        userAsscTXT.Text = dataReader.GetValue(2).ToString();
                        IRDateTXT.Text = dataReader.GetValue(3).ToString();
                        IRNumTXT.Text = dataReader.GetValue(4).ToString();
                        DescriptionTXT.Text = dataReader.GetValue(5).ToString();
                        summaryTXT.Text = dataReader.GetValue(6).ToString();
                        AnalysisTXT.Text = dataReader.GetValue(7).ToString();
                        ConclusionTXT.Text = dataReader.GetValue(8).ToString();
    
                    }
                    dataReader.Close();
                    command.Dispose();
                    connection.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Can not open connection ! ");
                }
            }
    
    Monday, June 3, 2019 8:02 PM
  • User2148 posted

    this is not Binding, but it could works, have you tried?

    Monday, June 3, 2019 8:38 PM
  • User386302 posted

    Yeah I tried it and since it's not a sqlite reader it wouldn't work. I'm still researching but that's essentially what I'm trying to do.

    Monday, June 3, 2019 9:45 PM
  • User386302 posted

    So I think I am getting closer :o , just have to figure out how to write each value to their entry boxes:

    string entrydb = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),"Entry.db"); var db = new SQLiteConnection(entrydb);

    var getdata = db.Query("SELECT Title, Username, Password, URL, Notes FROM entrydb WHERE (Title='" + TitleViewList.SelectedItem + "')");

    Monday, June 3, 2019 10:56 PM
  • User382871 posted

    The data is successfully being inserted to the database so this is the only part where I am stuck. A basic demo about date binding. page.xaml.cs ``` public partial class Page2 : ContentPage { ObservableCollection models = new ObservableCollection(); public Page2() { InitializeComponent();

        models.Add(new model { date = Convert.ToDateTime("05/05/2012") });
        models.Add(new model { date = Convert.ToDateTime("08/09/2016") });
        models.Add(new model { date = DateTime.Now.Date });
    
        listview.ItemsSource = models;
    }
    

    }

    public class model { public string content { get; set; } public DateTime date { get; set; } } page.xaml ```

    Here is a sample which demonstrates a Todo list application where the data is stored and accessed in a local SQLite database. Binding is involved in this demo.

    Tuesday, June 4, 2019 2:44 AM
  • User386302 posted

    Hey Everyone,

    I found a solution works like a charm, see below!

            try
            {
                string entrydb = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), 
               "Entry.db");
                var db = new SQLiteConnection(entrydb);
    
    
                var getdata= db.Query<CreatedEntry>("SELECT Password FROM CreatedEntry WHERE (Title='" + 
                TitleViewList.SelectedItem + "')");
                foreach (var s in getdata)
                {
                    DisplayAlert("success", s.Password, "ok");
                }
    
            }
            catch
            {
    
            }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 5, 2019 2:06 AM