Click here to Skip to main content
16,017,261 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Heloo,

I have tow class.

DatabaseFactory.cs

C#
....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..
C#
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:

C#
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.
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900