我有以下代码从存储过程中读取数据集,然后将其保存在列表中。存储过程中的数据集工作正常,它返回带有值的表。但是在将其保存到列表中时,我不断收到异常。
代码是
public class mList
{
public DateTime Ee { get; set; }
public DateTime ndate { get; set; }
public int SNo { get; set; }
public int CId { get; set; }
public int rID { get; set; }
}
internal class Program
{
private static void Main(string[] args)
{
string procName = "listest";
SqlConnection conn=new SqlConnection(cs);
try
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(procName, conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
da.Fill(ds);
ds.Tables["t0"].TableName = "Rows";
List<mL> newlist = ds.Tables["t0"].AsEnumerable().Select(row => new mList
{
Ee = row.Field<DateTime?>(0).GetValueOrDefault(),
ndate = row.Field<DateTime?>(1).GetValueOrDefault(),
SNo = row.Field<int?>(2).GetValueOrDefault(),
CId = row.Field<int?>(3).GetValueOrDefault(),
rID = row.Field<int?>(4).GetValueOrDefault()
}).ToList();
}
}
我得到的例外是System.ArgumentNullException was caught, Message=Value cannot be null.