vendredi 25 septembre 2015

Acess to all the data from the database in windows phone 8.1 C#

That's my problem, I need to use sqlite in my wp8.1 app, i have install the nugets, extensions etc.. i Have 3 textblock: i need to set the textblock text from a database, for example i have a database, with 3 different names inside. i need to set the Mussolinitext.text to the first item of the db in Colummn "Personaggi" (Benito Mussolini ) and ciampitext.text to the second item of the db. The same with "Luoghi", 3 textbox and 3 data from the database to set in order like: abazia.text = (//first database item) roma.text = (//second database item)

 private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        SQLiteAsyncConnection conn = new SQLiteAsyncConnection("database.db");

        await conn.RunInTransactionAsync(async (connection) =>
        {
            Person person = new Person
            {
                Name = "Mussolini",
                Personaggi = ""
            };

            await connection.InsertAsync(person);
        });
    }


private async void Button_Click_2(object sender, RoutedEventArgs e)
    {
        SQLiteAsyncConnection conn = new SQLiteAsyncConnection("database.db");

        var query = conn.Table<Person>().Where(x => x.Name == "Matteo");
        var result = await query.ToListAsync();
        foreach (var item in result)
        {
            //  MessageDialog dialog = new MessageDialog(string.Format("{0}: {1} {2}", item.Id, item.Name, item.Surname));
            // await dialog.ShowAsync();

            Mussolinitext.Text = item.Name;
            Ciampitext.Text = item.Name;
            Pietrotext.Text = item.Name;


        }
    }

the problem is that, i need to acces to all the database, not just the first data !

<HyperlinkButton Click="HyperlinkButtonP_Click">
                    <StackPanel>
                        <TextBlock Text="Benito Mussolini" x:Name="Mussolinitext" FontSize="32"/>
                        <Image Source="Assets/images/benito_mussolini.jpg"/>
                    </StackPanel>
                </HyperlinkButton>
                <HyperlinkButton Click="HyperlinkButtonP1_Click">
                    <StackPanel>
                        <TextBlock Text="Carlo Azelio Ciampi"  x:Name="Ciampitext" FontSize="32"/>
                        <Image Source="Assets/images/Ciampi.jpg"/>
                    </StackPanel>
                </HyperlinkButton>
                <HyperlinkButton Click="HyperlinkButtonP2_Click">
                    <StackPanel>
                        <TextBlock Text="Pietro Aretino"  x:Name="Pietrotext" FontSize="32"/>
                        <Image Source="Assets/images/aretino.jpg"/>
                    </StackPanel>
                </HyperlinkButton>

Here's the database:+--------+------------+ | Luoghi | PersonaggI | +--------+------------+ | Abazia | Mussolini | | Roma | Ciampi | | Africa | Pietro | +--------+------------+

My problem is that all textbox are "Matteo". i need my database, not "matteo" everywhere. thnks

Aucun commentaire:

Enregistrer un commentaire