我正在尝试将一个类强制转换为接口。我得到了这个例外。
我试图观察所有使用过的元素,但似乎一切正常。
![代码异常] https://i.imgur.com/twY6Bl2.png 我的IStocarePacienti接口代码是:
namespace DataAccess
{
public interface IStocarePacienti : IStocareFactory
{
List<Pacient> GetPacienti();
Pacient GetPacient(int id);
bool AddPacient(Pacient d);
bool UpdatePacient(Pacient d);
}
}
对于我的班级:
namespace DataAccess
{
public class AdministrarePacienti : IStocareFactory
{
private const int PRIMUL_TABEL = 0;
private const int PRIMA_LINIE = 0;
public List<Pacient> GetPacienti()
{
var result = new List<Pacient>();
var dsCompanii = SqlDBHelper.ExecuteDataSet("select * from pacienti_ac", CommandType.Text);
foreach (DataRow linieDB in dsCompanii.Tables[PRIMUL_TABEL].Rows)
{
result.Add(new Pacient(linieDB));
}
return result;
}
public Pacient GetPacient(int id)
{
Pacient result = null;
var dsCompanii = SqlDBHelper.ExecuteDataSet("select * from pacienti_ac where ID_PACIENT = :ID_PACIENT", CommandType.Text,
new OracleParameter(":ID_PACIENT", OracleDbType.Int32, id, ParameterDirection.Input));
if (dsCompanii.Tables[PRIMUL_TABEL].Rows.Count > 0)
{
DataRow linieDB = dsCompanii.Tables[PRIMUL_TABEL].Rows[PRIMA_LINIE];
result = new Pacient(linieDB);
}
return result;
}
public bool AddPacient(Pacient comp)
{
return SqlDBHelper.ExecuteNonQuery(
"INSERT INTO pacienti_ac VALUES (seq_pacienti_ac.nextval, :NUME, :PRENUME, :TELEFON, :GR_SANGUINA, :CNP, :DATA_NASTERII)", CommandType.Text,
new OracleParameter(":NUME", OracleDbType.NVarchar2, comp.Nume, ParameterDirection.Input),
new OracleParameter(":PRENUME", OracleDbType.NVarchar2, comp.Prenume, ParameterDirection.Input),
new OracleParameter(":TELEFON", OracleDbType.NVarchar2, comp.Telefon, ParameterDirection.Input),
new OracleParameter(":GR_SANGUINA", OracleDbType.NVarchar2, comp.GrSanguina, ParameterDirection.Input),
new OracleParameter(":CNP", OracleDbType.NVarchar2, comp.CNP, ParameterDirection.Input),
new OracleParameter(":DATA_NASTERII", OracleDbType.Date, comp.DataNasterii, ParameterDirection.Input));
}
public bool UpdatePacient(Pacient comp)
{
return SqlDBHelper.ExecuteNonQuery(
"UPDATE pacienti_ac set NUME = :NUME, PRENUME = :PRENUME, TELEFON = :TELEFON, GR_SANGUINA = :GR_SANGUINA, CNP = :CNP, DATA_NASTERII = :DATA_NASTERII where ID_PACIENT = :ID_PACIENT", CommandType.Text,
new OracleParameter(":NUME", OracleDbType.NVarchar2, comp.Nume, ParameterDirection.Input),
new OracleParameter(":PRENUME", OracleDbType.NVarchar2, comp.Prenume, ParameterDirection.Input),
new OracleParameter(":TELEFON", OracleDbType.NVarchar2, comp.Telefon, ParameterDirection.Input),
new OracleParameter(":GR_SANGUINA", OracleDbType.NVarchar2, comp.GrSanguina, ParameterDirection.Input),
new OracleParameter(":CNP", OracleDbType.NVarchar2, comp.CNP, ParameterDirection.Input),
new OracleParameter(":ID_PACIENT", OracleDbType.Int32, comp.IdPacient, ParameterDirection.Input));
}
}
}
我不知道该怎么办。正如我所说,一切对我来说都很好。