我正在创建一个databasehelper类,其中包含访问SQLCE数据库的方法.我想使用相同的方法使用包含与不同表中的字段匹配的属性的不同类来读取行.要使用的类是在运行时确定的,我想将包含类中对象的列表传递给方法,并获取属性名并使用它们来读取数据库.会非常方便,因为我可以将它用于我的所有(SQLCE-)数据库.
(我更新了错误的代码以便在这里提供解决方案)
#region ReadData
///----------------------------------------------------------------------
/// <summary>
/// Reads datarows from database and adds them to list.
/// </summary>
/// <param name="data">List containing objects with properties.</param>
/// <param name="table">Table in database.</param>
/// <param name="search">Substring of SQL-statement that follows 'WHERE'.</param>
/// <param name="connect">Connectionstring.</param>
/// <returns>true if successfull</returns>
///----------------------------------------------------------------------
public static bool ReadData<T>(List<T> data, string table, string search, string connect) where T : class, new()
{
// Return if input id missing
if (data == null || table == "" || connect …Run Code Online (Sandbox Code Playgroud)