ExeSql() публичный Метод

ִ��һ��SQL���(INSERT)���ص�ǰID
public ExeSql ( string sql, int a ) : int
sql string SQL���
a int ��ʱ����
Результат int
Пример #1
0
        public void WriteUser(User user)
        {
            string            sqlstr;
            DataRowCollection result = null;

            if (user != null && this.isConnected() == true)
            {
                sqlstr = "SELECT * FROM login WHERE username='******'";
                try
                {
                    result = db.GetDataTable(sqlstr).Rows;
                }
                catch (Exception)
                {
                    Console.WriteLine("Error: can't get user from database");
                    this.isconnected = false;
                    throw new Exception("can't get user from database");
                }
                if (result.Count > 0)
                {
                    sqlstr = string.Format("UPDATE login set password='******',sex={1},lastlogin='******' WHERE username='******'", user.Password, (int)user.Sex, user.lastLogin, user.Name);
                    try
                    {
                        db.ExeSql(sqlstr);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Error: can't create new user in database");
                        this.isconnected = false;
                        throw new Exception("can't create new user in database");
                    }
                }
                else
                {
                    sqlstr = string.Format("INSERT INTO login(username,password,sex,lastlogin) VALUES ('{0}','{1}',{2},'{3}')", user.Name, user.Password, (int)user.Sex, user.lastLogin);
                    try
                    {
                        db.ExeSql(sqlstr);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: can't create new user in database:" + ex.Message);
                        throw new Exception("can't create new user in database");
                    }
                }
            }
        }
Пример #2
0
        public void CreateChar(ref ActorPC aChar, int account_id)
        {
            string sqlstr;

            if (aChar != null && this.isConnected() == true)
            {
                string x, y, z;
                x = aChar.x.ToString();
                y = aChar.y.ToString();
                z = aChar.z.ToString();
                if (x.Contains(","))
                {
                    x.Replace(",", ".");
                }
                if (y.Contains(","))
                {
                    y.Replace(",", ".");
                }
                if (z.Contains(","))
                {
                    z.Replace(",", ".");
                }
                aChar.ShorcutIDs = new Dictionary <byte, ActorPC.Shortcut>();
                sqlstr           = string.Format("INSERT INTO chardata(account_id,name,face,details,sex,race,job," +
                                                 "cEXP,jEXP,cLevel, jLevel , pendingDeletion , validationKey , HP , maxHP , SP , maxSP , LC ," +
                                                 " maxLC , LP , maxLP , str , dex , intel , con , luk , stpoints , slots , weaponName , weaponType ," +
                                                 " GMLevel , mapID , worldID , x , y , z , sightRange , maxMoveRange ," +
                                                 " state , stance , guild , party , yaw , zeny , save_map , save_x , save_y ,  save_z ) VALUES ({0},N'{1}','{2}','{3}',{4},{5},{6},{7}," +
                                                 "{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22}," +
                                                 "{23},{24},{25},{26},'{27}',N'{28}',{29},{30},{31},{32},{33},{34},{35},{36},{37}," +
                                                 "{38},{39},{40},{41},{42},{43},{44},{45},{46},{47})",
                                                 account_id, aChar.name, bytes2HexString(aChar.face), bytes2HexString(aChar.details),
                                                 (int)aChar.sex, (int)aChar.race, (int)aChar.job, aChar.cExp, aChar.jExp, aChar.cLevel, aChar.jLevel, aChar.pendingDeletion,
                                                 aChar.validationKey, aChar.HP, aChar.maxHP, aChar.SP, aChar.maxSP, aChar.LC, aChar.maxLC, aChar.LP, aChar.maxLP,
                                                 aChar.str, aChar.dex, aChar.intel, aChar.con, aChar.luk, aChar.stpoints, bytes2HexString(aChar.slots), aChar.weaponName,
                                                 aChar.weaponType, aChar.GMLevel, aChar.mapID, aChar.worldID, x,
                                                 y, z, aChar.sightRange, aChar.maxMoveRange, aChar.state, aChar.stance,
                                                 aChar.guild, aChar.party, aChar.yaw, aChar.zeny, aChar.save_map, aChar.save_x, aChar.save_y, aChar.save_z);
                try
                {
                    aChar.charID = (uint)db.ExeSql(sqlstr, 0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: can't create new char in database" + ex.Message);
                    throw new Exception("can't create new char in database");
                }
                //aChar.charID = getCharID( aChar.name );
                SaveInv(aChar);
                SaveWeapon(aChar);
                SaveSkills(aChar);
                SaveQuest(aChar);
            }
        }