如何通过mysql数据库在xamarin android中进行授权?
这里代码:
MysqlCommand com = new MysqlCommand("SELECT test_log, test_pass FROM login WHERE test_log =@log AND test_pass =@pass", mycon);
mycon.Open();
com.Parameters.AddWithValue("@log", login1.Text);
com.Parameters.AddWithValue("@pass", password1.Text);
MySqlReader dr = com.ExcecuteReader();
下载所有链接并连接MysqlClient。请帮忙!
答案 0 :(得分:0)
如何通过mysql数据库在xamarin android中进行授权?
我不知道您目前使用的是哪个库,但您可以尝试使用MySQL Plugin。您可以通过Component->Edit Components-> Get More Components->Search MySQL Plugin on the search bar
将其添加到项目中。
然后您可以使用以下代码访问MySQL:
public bool loginFromMySQL()
{
MySqlConnection sqlconn=null;
bool loginSuccess=false;
try
{
string connsqlstring = "Server=serverAddress;Port=3306;database=database Name;User Id=userName;Password=user password;charset=utf8";
sqlconn = new MySqlConnection(connsqlstring);
sqlconn.Open();
DataSet tickets = new DataSet();
string userName = "userName";
string password = "password";
string queryString = "select * from login where userName='" + userName + "' and password='" + password + "'";
MySqlDataAdapter adapter = new MySqlDataAdapter(queryString, sqlconn);
adapter.Fill(tickets, "login");
if (tickets.Tables["login"].Rows.Count > 0)
{
//login success
loginSuccess=true;
}
else
{
loginSuccess=false;
}
}
catch (Exception e)
{
Console.Write(e.Message);
}
sqlconn.Close();
return loginSuccess;
}