我已经创建了表并将几行放入它。有没有办法从表中解析我自己的对象?解析来自sql的对象
class Human
{
string name;
int age;
public Human(string name, int age)
{
this.name = name;
this.age = age;
}
}
-- create table
string sql = "create table human (name varchar(20), age int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
-- insert sample data
string sql = "insert into human (name, age) values ('John', 20)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
-- get the data back from that table
string sql = "select * from human";
command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
现在我该如何解析我的阅读器中的Human
实例?
另请参见:在上一个查询中,**在调用'.executeReader'后不要调用'.ExecuteQuery()'!只需一个电话 - 既然你想要找回结果集,你需要'.ExecuteReader()'.... –
@marc_s这是一个问题的样本,它不是一个真正的代码,但无论如何 - 谢谢! – Azi