Jump to content

Recommended Posts

Posted

I'm trying to make a way to remove the tunning from the database.

Here is the part of the TunningSide (Server-Side C#)

    public static int AddTune(TunningModel tunning)
        {
            int tunningId = 0;
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                try
                {
                    connection.Open();
                    MySqlCommand command = connection.CreateCommand();

                    command.CommandText = "INSERT INTO tunning (vehicle, slot, component) VALUES (@vehicle, @slot, @component)";
                    command.Parameters.AddWithValue("@vehicle", tunning.vehicle);
                    command.Parameters.AddWithValue("@slot", tunning.slot);
                    command.Parameters.AddWithValue("@component", tunning.component);

                    command.ExecuteNonQuery();
                    tunningId = (int)command.LastInsertedId;
                }
                catch (Exception ex)
                {
                    NAPI.Util.ConsoleOutput("[Tunning Added] " + ex.Message);
                }
            }

            return tunningId;
        }

      public static List<TunningModel> LoadTunnings()
        {
            List<TunningModel> tunningList = new List<TunningModel>();

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                MySqlCommand command = connection.CreateCommand();
                command.CommandText = "SELECT * FROM tunning";

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        TunningModel tunning = new TunningModel();

                        tunning.id = reader.GetInt32("id");
                        tunning.vehicle = reader.GetInt32("vehicle");
                        tunning.slot = reader.GetInt32("slot");
                        tunning.component = reader.GetInt32("component");

                        tunningList.Add(tunning);
                    }
                }
            }

            return tunningList;
        }

 

Here the side of the RemoveTunning (Server-Side)

[RemoteEvent("RemoveTunning")]
public void RemoveTunningEvent(Client player, int id)
	{
	int vehicleId = player.Vehicle.GetData(EntityData.VEHICLE_ID);
	TunningModel tunningModel = new TunningModel();
	{
	tunningModel.id = vehicleId;
	}
	Task.Factory.StartNew(() =>
		{
		Database.RemoveTunning(tunningModel);
		});
	}

public static void RemoveTunning(TunningModel tunning)
     {
        using (MySqlConnection connection = new MySqlConnection(connectionString))
           {
            try
               {
                connection.Open();
                MySqlCommand command = connection.CreateCommand();
	            command.CommandText = "DELETE FROM `tunning` WHERE `tunning`.`id` = @id LIMIT 1";
                command.Parameters.AddWithValue("@id", tunning.id);
                command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                NAPI.Util.ConsoleOutput("[EXCEPTION Tunning Removed] " + ex.Message);
                }
            }
        }

RemoveTunning ClientSide:

		private void RemoveTunningEvent(object[] args)
		{
			// Get the variables from the array
			int id = Convert.ToInt32(args[1]);
			Events.CallRemote("RemoveTunning", id);
		}

 

Posted

Cool, maybe tell us what is wrong, how is your code acting in game? So we just don't read 100 lines of code without any exception message.

Debug ur incoming "tunning.id" while trying to delete it and check if it's the correct one.

Posted

Well i dont know what is wrong because when i call the RemoveTunning event, it not works, the tunning exist in database and nothing getting removed.

 

 

Posted (edited)
available from text:
vehicle, slot, component
"DELETE FROM `tunning` WHERE `tunning`.`id` = @id LIMIT 1"

change code
"DELETE FROM `tunning` WHERE 'vehicle' = @id LIMIT 1"
This will delete the first component for the given vehicle id.


public void RemoveTunningEvent(Client player, int id)
Never used in preview code

 

 

 

 

Edited by nachos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...