I have saved datas in COMPANY_MASTER tabe in sqlite where id =1 and when i load that form again i want that data to be displayed in the controls.
Xaml code
` <ContentPage.ToolbarItems>
<ToolbarItem Text="Edit" Activated="OnEdit" Order="Secondary"/>
<ToolbarItem Text="Save" Activated="OnSave" Order="Primary" />
</ContentPage.ToolbarItems>
<ContentView>
<ScrollView>
<StackLayout>
<Grid x:Name="gridLayout" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label Text="Company Name" Grid.Row="0" Grid.Column="0"/>
<Entry x:Name="ECompnyName" HorizontalOptions="FillAndExpand" Grid.Row="0" Grid.Column="1" IsEnabled="False" Text="{Binding Name}"/>
<Label Text="Company Address" Grid.Row="1" Grid.Column="0"/>
<Entry x:Name="ECompnyAdd1" HorizontalOptions="FillAndExpand" Grid.Row="1" Grid.Column="1" IsEnabled="False" Text="{Binding Address1}"/>
<Entry x:Name="ECompnyAdd2" HorizontalOptions="FillAndExpand" Grid.Row="2" Grid.Column="1" IsEnabled="False" Text="{Binding Address2}"/>
<Entry x:Name="ECompnyAdd3" HorizontalOptions="FillAndExpand" Grid.Row="3" Grid.Column="1" IsEnabled="False" Text="{Binding Address3}"/>
<Label Text="``Company Email Id" Grid.Row="4" Grid.Column="0"/>
<Entry x:Name="ECompnyEmail" HorizontalOptions="FillAndExpand" Grid.Row="4" Grid.Column="1" IsEnabled="False" Text="{Binding Email}"/>
<Label Text="Company Phone" Grid.Row="5" Grid.Column="0"/>
<Entry x:Name="ECompnyPhone" HorizontalOptions="FillAndExpand" Grid.Row="5" Grid.Column="1" IsEnabled="False" Text="{Binding PhoneNo}"/>
<Label Text="Company Type" Grid.Row="6" Grid.Column="0" Margin="3" />
<Picker x:Name="pickCompnyType" Grid.Row="6" Grid.Column="1" IsEnabled="False" >
<Picker.Items>
<x:String>Academic</x:String>
<x:String>Financial</x:String>
</Picker.Items>
</Picker>
<Label Text="Wing" Grid.Row="7" Grid.Column="0"/>
<Entry x:Name="EWing" HorizontalOptions="FillAndExpand" Grid.Row="7" Grid.Column="1" IsEnabled="False" Text="{Binding Wing}"/>
<Label Text="Year" Grid.Row="8" Grid.Column="0" Margin="3" />
<Picker x:Name="pickYear" Grid.Row="8" Grid.Column="1" IsEnabled="False" >
<Picker.Items>
<x:String>April - March</x:String>
<x:String>January - December</x:String>
</Picker.Items>
</Picker>
</Grid>
</StackLayout>
</ScrollView>
</ContentView> `
xaml.cs
` private string type;
private string year;
private SQLiteAsyncConnection _connection;
public frmSettings ()
{
InitializeComponent ();
_connection = DependencyService.Get<ISQLiteDb>().GetConnection();
}
protected async override void OnAppearing()
{
await _connection.CreateTableAsync<COMPANY_MASTER>();
base.OnAppearing();
}
private void OnEdit(object sender, EventArgs e)
{
ECompnyName.IsEnabled = true;
ECompnyAdd1.IsEnabled = true;
ECompnyAdd2.IsEnabled = true;
ECompnyAdd3.IsEnabled = true;
ECompnyEmail.IsEnabled = true;
ECompnyPhone.IsEnabled = true;
pickCompnyType.IsEnabled = true;
pickYear.IsEnabled = true;
EWing.IsEnabled = true;
}
private async void OnSave(object sender, EventArgs e)
{
try
{
if (pickCompnyType.SelectedIndex == 0)
{
type = "Academic";
}
else if(pickCompnyType.SelectedIndex == 1)
{
type = "Financial";
}
if (pickYear.SelectedIndex == 0)
{
year =" April - March";
}
else if(pickYear.SelectedIndex==1)
{
year = "January - December";
}
var cmpny = new COMPANY_MASTER
{
Name = ECompnyName.Text,
PhoneNo = ECompnyPhone.Text,
Email = ECompnyEmail.Text,
Address1 = ECompnyAdd1.Text,
Address2 = ECompnyAdd2.Text,
Address3 = ECompnyAdd3.Text,
Type = type,
Wing = EWing.Text,
Year =year
};
var checker = await _connection.InsertAsync(cmpny);
if (checker == 1)
{
await DisplayAlert("Message", "Data saved successfully.", "Ok")
await Navigation.PopAsync();
}
}
catch
{
await DisplayAlert("Error", "Error in data saving. Please retry later.", "Ok");
}
}`