List<string> 到 Alertcontroller
List<string> to Alertcontroller
菜鸟问题....我是开发应用程序的新手,我希望这个问题不会太愚蠢。
我的数据库中有一个包含公司的 TableView。当我滑动时,我想要有 3 个选项。
1. 在 AlertController 中显示有关所选公司的信息
2.管理有关所选公司的一些信息
3.删除所选公司
我的问题是针对案例 1。
刷卡功能生效,出现AlertController。但是我的数据库中的信息有以下错误消息:
System.Collection.Generic.List'1[Systen.String]
picture
如果需要孔码,我可以上传。我希望这两部分足够了。
我的代码:
public partial class ListViewController : UITableViewController
{
public ListViewController(IntPtr handle) : base(handle)
{
}
List<string> words = new List<string>();
List<string> adresse = new List<string>();
.....
public UIContextualAction ContextualFlagAction(int row)
{
var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal,
"Flag",
(FlagAction, view, success) => {
var alertController = UIAlertController.Create($"Information über {words[row]}", $"Straße: {adresse}", UIAlertControllerStyle.Alert);
//kuddelmuddel beginnt
using (MySqlConnection connection2 = new MySqlConnection("Connection String"))
{
string query = $"SELECT Strasse FROM Kunden WHERE Firma LIKE '{words[row]}'";
MySqlCommand command = new MySqlCommand(query, connection2);
connection2.Open();
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
adresse.Add(reader.GetString(0));
}
}
}
//kuddelmuddel endet
alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
PresentViewController(alertController, true, null);
success(true);
});
action.Image = UIImage.FromFile("feedback.png");
action.BackgroundColor = UIColor.Blue;
return action;
}
@Jason 说,错误是将列表视为 string.And 在数据库操作后显示警报。
修改
using (MySqlConnection connection2 = new MySqlConnection("Connection String"))
{
string query = $"SELECT Strasse FROM Kunden WHERE Firma LIKE '{words[row]}'";
MySqlCommand command = new MySqlCommand(query, connection2);
connection2.Open();
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
adresse.Add(reader.GetString(0));
}
}
}
var alertController = UIAlertController.Create($"Information über {words[row]}", $"Straße: {adresse[0]}", UIAlertControllerStyle.Alert);
alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
PresentViewController(alertController, true, null);
菜鸟问题....我是开发应用程序的新手,我希望这个问题不会太愚蠢。
我的数据库中有一个包含公司的 TableView。当我滑动时,我想要有 3 个选项。
1. 在 AlertController 中显示有关所选公司的信息
2.管理有关所选公司的一些信息
3.删除所选公司
我的问题是针对案例 1。
刷卡功能生效,出现AlertController。但是我的数据库中的信息有以下错误消息:System.Collection.Generic.List'1[Systen.String]
picture
如果需要孔码,我可以上传。我希望这两部分足够了。
我的代码:
public partial class ListViewController : UITableViewController
{
public ListViewController(IntPtr handle) : base(handle)
{
}
List<string> words = new List<string>();
List<string> adresse = new List<string>();
.....
public UIContextualAction ContextualFlagAction(int row)
{
var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal,
"Flag",
(FlagAction, view, success) => {
var alertController = UIAlertController.Create($"Information über {words[row]}", $"Straße: {adresse}", UIAlertControllerStyle.Alert);
//kuddelmuddel beginnt
using (MySqlConnection connection2 = new MySqlConnection("Connection String"))
{
string query = $"SELECT Strasse FROM Kunden WHERE Firma LIKE '{words[row]}'";
MySqlCommand command = new MySqlCommand(query, connection2);
connection2.Open();
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
adresse.Add(reader.GetString(0));
}
}
}
//kuddelmuddel endet
alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
PresentViewController(alertController, true, null);
success(true);
});
action.Image = UIImage.FromFile("feedback.png");
action.BackgroundColor = UIColor.Blue;
return action;
}
@Jason 说,错误是将列表视为 string.And 在数据库操作后显示警报。
修改
using (MySqlConnection connection2 = new MySqlConnection("Connection String"))
{
string query = $"SELECT Strasse FROM Kunden WHERE Firma LIKE '{words[row]}'";
MySqlCommand command = new MySqlCommand(query, connection2);
connection2.Open();
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
adresse.Add(reader.GetString(0));
}
}
}
var alertController = UIAlertController.Create($"Information über {words[row]}", $"Straße: {adresse[0]}", UIAlertControllerStyle.Alert);
alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
PresentViewController(alertController, true, null);