如何将SqlDataReader dr转化为list<>
定义了一个A类,有各种属性。
在定义一个B类,里面有SMB()方法。
public static List<A> SMB()
{
SqlConnection con = new SqlConnection("********");/
con.Open();
SqlCommand com = new SqlCommand("select id,zie from yysk", con);
SqlDataReader dr = com.ExecuteReader();//执行SQL语句
return dr;//这里报错,请问我怎么转化成list<A>类型
}
------解决方案--------------------public class MyObj
{
public string Name;
public double Value;
}
List<MyObj> result;
using (var conn = new OracleConnection(cnStr))
{
conn.Open();
var comm = conn.CreateCommand();
comm.CommandText = "select e.TheName, e.Number from Users as e where ..........";
comm.CommandType = System.Data.CommandType.Text;
result = ( from DbDataRecord record in comm.ExecuteReader() select new MyObj{
Name = (string)record["TheName"],
Value = (double)record["Number"]
&nbs