以xamarin形式将选取器项目值插入数据库(firebase)

w41d8nur  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(99)

我的问题是将数据以xamarin的形式插入到firebase中。这是我的CreateAccount.xaml。

<Picker 
                                Title="Select Security Question" 
                                TextColor="Black"
                                HorizontalOptions="StartAndExpand"
                                FontSize="Medium"
                                WidthRequest="250"
                                TitleColor="Black"
                                x:Name="entryField_SecurityQuestion"
                                >
                                <Picker.Items 
                                
                                    >
                                
                                    <x:String>
                                        Who is your first love?
                                    </x:String>
                                    <x:String>
                                       what subject you failed?
                                    </x:String>
                                     <x:String>
                                       What is the name of your dog?
                                    </x:String>
                                     <x:String>
                                       Who is your first kiss?
                                    </x:String>
                                    
                                </Picker.Items>
                                
                            </Picker>

codebehind.cs

async public void signButton_Clicked(System.Object sender, System.EventArgs e)
        {

           Picker picker = sender as Picker;

            //this is how I manage my some ID from my front end
            string firstName = entryField_Firstname.Text;
            string lastName = entryField_Lastname.Text;
            string contactNumber = entryField_PhoneNumber.Text;

             string securityQuestion = picker.SelectedItem.ToString(); // this line is my trial and error, I tried some code but I cant insert data to database

            Customer customer = new Customer();
            customer.FirstName = firstName;
            customer.LastName = lastName;
            customer.SecurityQuestion = securityQuestion;//this one also, this is my trial and error approach 
            customer.ContactNumber = contactNumber;

            var Savedata = await customerRepo.Save(customer);
         }

`
我希望,我可以得到采摘的项目,并将其保存到数据库。任何链接,将张贴相关的我的职位,将不胜感激。谢谢你这么多

pepwfjgg

pepwfjgg1#

如果你想得到Picker的SelectedItem,你需要引用你的picker的x:Name="entryField_SecurityQuestion"而不是Picker picker = sender as Picker;,就像Jason说的那样。
可以参考下面的代码:

private void signButton_Clicked(object sender, EventArgs e) 
    { 
       // remove the following code
        //Picker picker = sender as Picker;
         
        string securityQuestion = entryField_SecurityQuestion.SelectedItem.ToString();

        Customer customer = new Customer();
        customer.FirstName = firstName;
        customer.LastName = lastName;
        customer.SecurityQuestion = securityQuestion;

    }

相关问题