我發現有這麼多人問這個錯誤,但我可以找到一個解釋的正確答案。不包含帶1個參數「4」的構造函數
類別:Update
public class Log
{
public int id { get; set; }
public string description { get; set; }
public string type { get; set; }
public string action { get; set; }
public DateTime date { get; set; }
public string fullname { set; get; }
public Log() {
}
public Log(LogDs.LogFileRow row)
{
this.id = row.id;
this.type = row.type;
this.action = row.action.ToString();
this.description = row.description.ToString();
this.date = row.date;
this.fullname = row.fullname;
}
}
BC類:
public class LogBC
{
LogDalc dalc = new LogDalc();
public List<Log> List(DateTime dateStart, DateTime dateEnd)
{
List<Log> listLog = new List<Log>();
LogDs.LogFileDataTable dt = dalc.Sel(dateStart, dateEnd);
for (int i = 0; i < dt.Count; i++)
{
Log exp = new Log(dt[i]);
listLog.Add(exp);
}
return listLog;
}
DALC類別:示於BC類
public class LogDalc: BaseDalc
{
public LogDs.LogFileDataTable Sel(DateTime dateStart, DateTime dateEnd)
{
LogDs ds = new LogDs();
using (SqlConnection con = new SqlConnection(Global.Config.ConnStr))
{
SqlCommand cmd = new SqlCommand("spp_txn_expenses_sel", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@sdate", dateStart == DateTime.MinValue ? dbNull : dateStart));
cmd.Parameters.Add(new SqlParameter("@edate", dateEnd == DateTime.MinValue ? dbNull : dateEnd));
FillDataSet(cmd, ds, new string[] { ds.LogFile.TableName });
}
return ds.LogFile;
}
}
誤差和精確地Log exp = new Log(dt[i]);
。任何人都可以解釋爲什麼發生這種情況以及如何解決它?
錯誤很簡單。您創建'Log'的新實例並在創建它時傳遞'dt [i]'。但是'Log'類中沒有接受參數的構造函數。 –
不包含帶1個參數的構造函數。 – Valentin
我用構造函數更新了我的代碼,但仍顯示相同的錯誤 – Saif