Noob question....i am new into developing apps, i hope this question isn't too stupid.
I have a TableView with companys from my database. When I Swipe, I want to have 3 options.
1. Show Information about the selected Company in an AlertController
2. Manage some Information about the selected Company
3. Delete the selected Company
My Question is for Case 1.
The swipe function works and the AlertController appears. But I have the following error message for the Information from my database:System.Collection.Generic.List'1[Systen.String]
If you need the hole Code, I can upload it. I hope these two parts are enough.
My code:
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 said, the error comes with treating the list as a string.And make the alert show after the db operation.
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);