Ejemplo n.º 1
0
        public static int Delete <T>(string DatabaseTable, string wherePropertie, string whereValue)
        {
            string databaseString = "delete from dbo." + DatabaseTable;

            databaseString += " where " + wherePropertie + "=" + whereValue;

            return(SqlDataAccess.ExecuteDataString(databaseString));
        }
Ejemplo n.º 2
0
        public static int Create <T>(T Data, string DatabaseTable, bool autoIncrease = true, string IdString = "Id")
        {
            string databaseString = "insert into dbo." + DatabaseTable + " ";
            Type   t = Data.GetType();

            PropertyInfo[] props = t.GetProperties();

            if (autoIncrease)
            {
                var pid = props.First(p => p.Name == IdString);

                pid.SetValue(Data, Count(Data, DatabaseTable));
            }

            databaseString += "(";
            for (int i = 0; i < props.Length; i++)
            {
                databaseString += props[i].Name;
                if (i < props.Length - 1)
                {
                    databaseString += ", ";
                }
            }

            databaseString += ") values (";
            for (int i = 0; i < props.Length; i++)
            {
                databaseString += "'";
                databaseString += props[i].GetValue(Data);
                databaseString += "'";
                if (i < props.Length - 1)
                {
                    databaseString += ", ";
                }
            }
            databaseString += ")";

            return(SqlDataAccess.ExecuteDataString(databaseString));
        }
Ejemplo n.º 3
0
        public static int Update <T>(T Data, string DatabaseTable, string wherePropertie)
        {
            string databaseString = "update dbo." + DatabaseTable + " set ";
            Type   t = Data.GetType();

            PropertyInfo[] props = t.GetProperties();
            for (int i = 0; i < props.Length; i++)
            {
                databaseString += props[i].Name + "=" + props[i].GetValue(Data);
                if (i < props.Length - 1)
                {
                    databaseString += ", ";
                }
            }

            PropertyInfo whereCase = props.First(p => p.Name == wherePropertie);

            if (whereCase != null)
            {
                databaseString += " where " + wherePropertie + "=" + whereCase.GetValue(Data);
            }

            return(SqlDataAccess.ExecuteDataString(databaseString));
        }