I have 'Stolen' some code from another answer by Dummy01 in following question: How can I populate a list with values from a SQL Server database?
The problem is that I want to get a list of Objects instead of strings
How would I have to modify this code to do so? Help much appreciated.
The problem occurs in this part of the code where I don't know what type to specify.
if (!reader.IsDBNull(0))
tagsList.Add(reader.GetString(0));
Code:
private void LoadList()
{
List<string> tagsList = new List<string>();
using (IDbConnection connection = new SqlConnection(Properties.Settings.Default.DBConnectionString))
{
connection.Open();
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT TAGCOLUMN FROM TAGSTABLE";
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
if (!reader.IsDBNull(0))
tagsList.Add(reader.GetString(0));
}
reader.Close();
}
}
connection.Close();
}
}