Пример #1
0
        public void deleteWithId <T>(T table)
        {
            SqlParameter paramater = InfoClass.getId(table);
            string       tableName = InfoClass.getClassName(table);

            ReadInDataBase("Delete FROM " + tableName.ToUpper() + " WHERE " + paramater.ParameterName + "=" + paramater.Value);
        }
Пример #2
0
        public SqlDataReader selectWithID <T>(T table, int id)
        {
            SqlParameter paramater = InfoClass.getId(table);
            string       tableName = InfoClass.getClassName(table);

            return(ReadInDataBase("SELECT * FROM " + tableName.ToUpper() + " WHERE " + paramater.ParameterName + "=" + paramater.Value));
        }
Пример #3
0
        public void update <T>(T table)
        {
            string        tableName = InfoClass.getClassName(table);
            StringBuilder sb        = new StringBuilder("UPDATE " + tableName + " SET ");

            SqlParameter[] attributeNames = InfoClass.getPropertyNames(table);
            int            tableLength    = attributeNames.Length - 1;

            //We don't take the class id
            for (int i = 1; i < tableLength; i++)
            {
                sb.Append(attributeNames[i].ParameterName + "=" + "@" + attributeNames[i].ParameterName + ", ");
            }
            sb.Append(attributeNames[tableLength].ParameterName + "=" + "@" + attributeNames[tableLength].ParameterName);
            sb.Append(" WHERE " + attributeNames[0].ParameterName + "=" + attributeNames[0].Value);
            WriteInDatabase(sb.ToString(), attributeNames);
        }
Пример #4
0
        public void insert <T>(T table)
        {
            string        tableName = InfoClass.getClassName(table);
            StringBuilder sb        = new StringBuilder("Insert into " + tableName);

            SqlParameter[] attributeNames = InfoClass.getPropertyNames(table);
            int            tableLength    = attributeNames.Length - 1;

            //column where we need to add values
            for (int i = 1; i < tableLength; i++)
            {
                sb.Append(attributeNames[i].ParameterName + ", ");
            }
            sb.Append(attributeNames[tableLength].ParameterName + ")");
            //values of the columns
            sb.Append(" VALUES (");
            for (int i = 1; i < tableLength; i++)
            {
                sb.Append("@" + attributeNames[i].ParameterName + ", ");
            }
            sb.Append("@" + attributeNames[tableLength].ParameterName + ")");

            WriteInDatabase(sb.ToString(), attributeNames);
        }
Пример #5
0
        public SqlDataReader selectAll <T>(T table)
        {
            string tableName = InfoClass.getClassName(table);

            return(ReadInDataBase("SELECT * FROM " + tableName.ToUpper()));
        }