Below is a method for selecting from a mysql table. However I do not find it very dynamic. Coming from PHP all I do is send a query to a function and recieve its data in a variable. This is no longer the case it seems.
My queries vary a lot. Sometimes they only get one row and one column. Next time it may collect 1000 rows and all columns. Using the list the way below is not very dynamic and I do not wish to build a select method for each possible scenario.
I wish to run my query, return the data and let me do what I want with it.
public List<string>[] Select(string query)
{
//Create a list to store the result
List<string>[] list = new List<string>[3];
list[0] = new List<string>();
//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["id"] + "");
list[1].Add(dataReader["name"] + "");
list[2].Add(dataReader["age"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return list;
}
else
{
return list;
}
}
Thanks!