Heloo,
I have tow class.
DatabaseFactory.cs
....partial code
internal static Contract LoadContract(int contractId)
{
IDataReader reader = ExecuteSQL("select * from [Contracts] where ([ContractId] = @ContractId)", new IDbDataParameter[] { CreateParameter("@ContractId", OleDbType.BigInt, contractId) });
if (!reader.Read())
{
throw new Exception(string.Format("Contractul {0} nu a fost gasit.", contractId));
}
return new Contract(reader);
}
.....
and class 2.
Contract.cs
partial code..
public class Contract
{
private int clientId;
private int contractNumber;
private DateTime createDate;
private DateTime endDate;
private decimal procent;
private DateTime startDate;
public Contract()
{
this.startDate = DateTime.Now;
this.procent = Settings.Default.DefaultProcent;
}
public Contract(IDataReader reader)
{
this.startDate = DateTime.Now;
this.procent = Settings.Default.DefaultProcent;
this.contractNumber = (int) reader["ContractId"];
this.clientId = (int) reader["ClientId"];
this.createDate = (DateTime) reader["CreateDate"];
this.startDate = (DateTime) reader["StartDate"];
this.endDate = (DateTime) reader["EndDate"];
this.procent = (decimal) reader["Procent"];
}
public int ClientId
{
get
{
return this.clientId;
}
set
{
this.clientId = value;
}
}
I what to use DataTable instead of IdataReader.
I modifii the DatabaseFactory.cs to:
internal static Contract LoadContract(int contractId)
{
Program.Connection.CommandText = "select * from Contracts where ContractId=@ContractId";
Program.Connection.AddParameter("@ContractId", contractId);
DataTable Table = new DataTable();
Program.Connection.FillDataTable(Table, true);
if (Table.Rows.Count > 0)
{
throw new Exception(string.Format("Contractul {0} nu a fost gasit.", contractId));
}
return Table;
}
and i don't know how to modifing the second class. I need to return an ID from my database.