我们如何将日期插入SQLite数据库

时间:2019-05-03 01:02:59

标签: sqlite xamarin xamarin.forms

对于SQLite数据库中的每个数据插入,我也想插入current Date。如何在Xamarin Forms应用程序中做到这一点?

下面是我的代码,现在将一些状态数据插入数据库。

public void OnOKButtonClicked(object sender, EventArgs e)
        {
            overlay.IsVisible = false;
            DisplayAlert("Result",
                          string.Format("You entered {0}", EnteredStatus.Text), "OK");
            SoccerAvailability soccerAvailability = new SoccerAvailability();
            soccerAvailability.SoccerStatus = EnteredStatus.Text;

            var dailySoccerStatus = EnteredStatus.Text;
           int x = 0;
            try
            {
                if (!string.IsNullOrWhiteSpace(EnteredStatus.Text))
                {
                    //Insert the soccer status to the database:
                    x = conn.Insert(soccerAvailability);
                }
                else
                {
                    DisplayAlert("Soccer Availability", "Availability cannot be left blank", "OK");
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (x == 1)
            {

                Navigation.PushAsync(new Settings(soccerAvailability));
            }

            DisplaySoccerStatus();
        }

1 个答案:

答案 0 :(得分:2)

只需在您的CurrentDate模型上创建一个DateTime SoccerAvailability属性

soccerAvailability.CurrentDate = DateTime.Now;
x = conn.Insert(soccerAvailability);