Ejemplo n.º 1
0
        public bool createAndInsertToDB()
        {
            Console.WriteLine("createAndInsertToDB");
            //insert into yw_account(guid) values('8902');
            string cmdstring = "insert into " + tableName + " (";
            string values    = "values(";

            Type tp = GetType();

            List <string> columns = DBSerializer.getDBColoumns(tp);
            List <string> defines = DBSerializer.getDBDefines(tp);

            for (int i = 0; i < columns.Count; ++i)
            {
                cmdstring += columns[i] + ",";
                FieldInfo field = tp.GetField(columns[i]);
                values += "'" + DBSerializer.serializeField(field.FieldType, field.GetValue(this)) + "',";
            }

            cmdstring = cmdstring.Remove(cmdstring.Length - 1);
            values    = values.Remove(values.Length - 1);
            cmdstring = cmdstring + ") " + values + ");";
            Console.WriteLine("createAndInsertToDB:" + cmdstring);
            return(DataInitializer.DB_insert(tableName, cmdstring));;
        }
Ejemplo n.º 2
0
        private string getCreateString(Type tp)
        {
            string cmdString = "(";

            List <string> columns = DBSerializer.getDBColoumns(tp);
            List <string> defines = DBSerializer.getDBDefines(tp);

            for (int i = 0; i < columns.Count; ++i)
            {
                cmdString += columns[i];
                cmdString += " " + defines[i] + ",";
            }

            cmdString  = cmdString.Remove(cmdString.Length - 1, 1);
            cmdString += ");";
            Console.WriteLine("CmdString: " + cmdString);
            return(cmdString);
        }