Q:

Why my query return null

I want to ask why query return null and not update what i want.  Sorry I'm still new with asp.net and c#
myquery = "UPDATE kenderaan SET buatan = " + "'" + carmake + "'" + "," +
          "model = " + "'" + carmodel + "'" + "," +
          "no_enjin = " + "'" + carenjin + "'" + "," +
          "cc = " + carcc + "," +
          "seatCapacity = " + carseat + "," +
          "tahunBuatan = " + caryear + " WHERE no_kenderaan = " + "'" + carid + "'" + "," +
          "AND ic = " + "'" + cusid + "'";

connection = new DbConnection();
connection. Update(myquery);

A:

restructure your code into this, use Connection object, Command Object, using statement. 
string myquery = "UPDATE kenderaan SET buatan = @carmake ," +
              "     model = @carmodel ," +
              "     no_enjin =  @carenjin ," +
              "     cc = @carcc ," +
              "     seatCapacity =  @carseat ," +
              "     tahunBuatan = @caryear " +
              "WHERE no_kenderaan = @carid " +
              "     AND ic = @cusid ";

using (MySqlConnection _conn = new MySqlConnection("connectionStringHere"))
{
    using (MySqlCommand _comm = new  MySqlCommand())
    {
        _comm. Connection = _conn;
        _comm. CommandText = myquery;
        _comm. CommandType = CommandType. Text;
        _comm. Parameters. AddWithValue("@carmake",carmake);
        _comm. Parameters. AddWithValue("@carmodel",carmodel);
        _comm. Parameters. AddWithValue("@carenjin",carenjin);
        _comm. Parameters. AddWithValue("@carcc",carcc);
        _comm. Parameters. AddWithValue("@carseat",carseat);
        _comm. Parameters. AddWithValue("@caryear",caryear);
        _comm. Parameters. AddWithValue("@carid",carid);
        _comm. Parameters. AddWithValue("@cusid",cusid);

        try
        {
            _conn. Open();
            _comm. ExecuteNonQuery();
            MessageBox. Show("Updated!"); 
        }
        catch (MySqlException e)
        {
            MessageBox. Show(e. ToString()); // as mentioned on the comment
        }

    }
}

Reasons why you need to parameterized your query:

avoids SQL Injection
makes your code more readable
etc.. :D

Sources

AddWithValue
Add (recommended and leaving you this as an assignment :D)

