在调用fill之前,selectcommand属性是否尚未初始化?

问题描述:

公开列表<清单> GetCheckListDetails(int BusinessTypeId,int FilingTypeId)

{

List< checklist> list = new List< checklist>();

尝试

{

使用(var dao = DbActivity.Open())

{



CSqlDbCommand cmd = new CSqlDbCommand(DBProcedures.WorkOrderSearch.USP_INSERT_BUSINESSFILLING_DETAILS);



cmd.Parameters.AddWithValue(BusinessTypeId,BusinessTypeId);

cmd.Parameters.AddWithValue(FilingTypeId,FilingTypeId);

SqlDataAdapter da = new SqlDataAdapter() ;



DataSet ds = new DataSet();

da.Fill(ds);

list = (来自c在ds.Tables [0] .AsEnumerable()

选择新的CheckList()

{

CheckListId = c [0] .ToInt() ,

Deatil = c [1] .ToStr(),



})。ToList();

}



}



catch(例外情况)

{

Logger.Database.Error(ex.Message,ex);

throw;

}



返回列表;



}



这是我要执行的方法抛出一个名为selectcommand属性的错误,在调用fill之前还没有被初始化?如何解决?



提前感谢

public List<checklist> GetCheckListDetails(int BusinessTypeId, int FilingTypeId)
{
List<checklist> list = new List<checklist>();
try
{
using (var dao = DbActivity.Open())
{

CSqlDbCommand cmd = new CSqlDbCommand(DBProcedures.WorkOrderSearch.USP_INSERT_BUSINESSFILLING_DETAILS);

cmd.Parameters.AddWithValue("BusinessTypeId", BusinessTypeId);
cmd.Parameters.AddWithValue("FilingTypeId", FilingTypeId);
SqlDataAdapter da = new SqlDataAdapter();

DataSet ds = new DataSet();
da.Fill(ds);
list = (from c in ds.Tables[0].AsEnumerable()
select new CheckList()
{
CheckListId = c[0].ToInt(),
Deatil = c[1].ToStr(),

}).ToList();
}

}

catch (Exception ex)
{
Logger.Database.Error(ex.Message, ex);
throw;
}

return list;

}

this is my method to be executed and it is throwing an error called the selectcommand property has not been initialized before calling fill? how to fix it?

thanks in advance



在da.fill之前添加这个



da.selectcommand = cmd;
Hi
add this before da.fill

da.selectcommand=cmd;