c# - 将 Xamarin 应用注册页面连接到 MySQL 的 Azure 数据库
问题描述
我正在尝试构建 Xamarin 移动应用程序并希望将 Azure 数据库用于 MySQl 作为应用程序的数据库。
我已经为我的注册页面创建了设计。需要有关如何为 MySQl 创建 Azure 数据库以及如何将我的应用程序与其连接的帮助。我已经读到需要一个 API 来连接应用程序和数据库。在互联网上找不到任何示例来说明如何执行上述所有操作。
注册页面.XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="VeggiesUI.Views.RegistrationPage"
Shell.NavBarIsVisible="False"
Title="Registration"
BackgroundImageSource="OIP.jpg">
<StackLayout Margin="20,30,20,0" >
<Entry Placeholder="Enter First Name"
MaxLength="30"
Margin="5,0,5,10"/>
<Entry Placeholder="Enter Last Name"
MaxLength="30"
Margin="5,0,5,10"/>
<Entry Placeholder="Enter Email"
MaxLength="30"
Margin="5,0,5,10"/>
<Entry Placeholder="Enter Password"
MaxLength="15"
Margin="5,0,5,10"/>
<Entry Placeholder="Confirm Password"
MaxLength="15"
Margin="5,0,5,5"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.10*" />
<ColumnDefinition Width="0.90*" />
</Grid.ColumnDefinitions>
<CheckBox IsChecked="False"></CheckBox>
<Label Grid.Column="1"
Text=" Accept Ts and Cs."
Margin="0,5,5,0"/>
</Grid>
<Grid ColumnDefinitions="*,*">
<Button Text="Register"
Clicked="OnSaveButtonClicked"
BackgroundColor="LightGreen"
TextColor="Black"
Margin="0,10,5,0"/>
<Button Grid.Column="1"
Text="Clear"
BackgroundColor="LightGreen"
TextColor="Black"
Clicked="OnDeleteButtonClicked"
Margin="0,10,5,0"/>
</Grid>
<Button Text="Login Instead"
Clicked="OnButtonClicked"
TextColor="Blue"
BackgroundColor="Transparent"
BorderWidth="0"
CornerRadius="0"
WidthRequest="150"
FontSize="Medium"
/>
</StackLayout>
</ContentPage>
注册页面.XAML.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace VeggiesUI.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class RegistrationPage : ContentPage
{
public RegistrationPage()
{
InitializeComponent();
}
private void OnSaveButtonClicked(object sender, EventArgs e)
{
}
private void OnDeleteButtonClicked(object sender, EventArgs e)
{
}
private async void OnButtonClicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//LoginPage");
}
}
}
我是 Xamarin 和 Azure 的新手。
解决方案内容
解决方案
· 首先创建 Azure 移动服务(具有所需后端语言的数据库、服务器和表)
· 确保在项目中添加 Azure 移动 SDK 包。
· 有一个 itemTable.cs 类来定义要添加到数据库中的对象的属性
· 定义一个 Itemservice.cs 文件,在其中添加应用程序与 Azure 移动服务的所有交互
有关详细信息,请参阅本文如何构建连接到 Azure 的 Xamarin 应用程序 - Microsoft 技术社区
推荐阅读
- javascript - Android Webview 桌面通知支持
- c# - Object Reference Not Set to an Instance - Unity2D
- hyperledger-fabric - Hyperledger Fabric 和 Hyperledger Iroha 的区别?
- apache - Apache 本地虚拟主机已列出但不起作用
- reactjs - 无法在返回 jsx 中访问 Vue 实例
- serialization - 从 MFC 对话框保存文件
- python - Scrapy 产生深度为 2 的请求
- java - 未选中将 java.io.Serializable 强制转换为 java.util.ArrayList
- java - Tomcat 无法安装错误:Service was not (uninstalled)
- python - 从css节点scrapy中提取文本