Click here to Skip to main content
15,900,378 members

Comments by Mawool (Top 1 by date)

Mawool 11-Apr-14 22:35pm View    
please help me :(
Why updateCommand didnt work, but insert command work. below is my code like your code (with little manipulation):
public void SerahTerima(DataGridView dataGrid)
{
MySqlConnection connection = new MySqlConnection("SERVER=localhost;DATABASE=db_segel;UID=root;PASSWORD=;convert zero datetime=True");
MySqlDataAdapter adapter = new MySqlDataAdapter(); ;
DataTable table = new DataTable();
//this.adapter = new MySqlDataAdapter("SELECT * FROM `usage`", this.connection);
this.adapter = new MySqlDataAdapter("SELECT c.nama_pel, b.nomor, a.posisi, a.prev_segel, c.gardu, c.tarif, c.daya, a.tgl_pasang, a.id_segel, a.keterangan, c.id_pel, a.pelaksana, a.tgl_input FROM (`usage` a INNER JOIN `segel` b ON b.id_segel=a.id_segel) INNER JOIN `pelanggan` c ON c.id_pel = a.id_pelanggan ORDER BY a.tgl_pasang", this.connection);
MySqlCommand insert = new MySqlCommand("INSERT INTO `usage` values ('null', @s, @p, @pl, @t, @k, @ti, @tp, @po, @pr)", this.connection);
MySqlCommand update = new MySqlCommand("UPDATE segel SET status = 'Used' WHERE nomor = '@n'", this.connection);
insert.Parameters.Add("@s", MySqlDbType.Int32, 16, "id_segel");
insert.Parameters.Add("@p", MySqlDbType.VarChar, 12, "id_pel");
insert.Parameters.Add("@pl", MySqlDbType.VarChar, 32, "pelaksana");
insert.Parameters.Add("@t", MySqlDbType.VarChar, 4, "tarif");
insert.Parameters.Add("@k", MySqlDbType.Text, 255, "keterangan");
insert.Parameters.Add("@ti", MySqlDbType.Date, 16, "tgl_input");
insert.Parameters.Add("@tp", MySqlDbType.Date, 16, "tgl_pasang");
insert.Parameters.Add("@po", MySqlDbType.VarChar, 64, "posisi");
insert.Parameters.Add("@pr", MySqlDbType.VarChar, 16, "prev_segel");

update.Parameters.Add("@s", MySqlDbType.Int32, 16, "id_segel");
update.Parameters.Add("@n", MySqlDbType.VarChar, 16, "nomor");

this.adapter.InsertCommand = insert;
this.adapter.UpdateCommand = update;
this.adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
//// Save the data.
this.adapter.Update(this.table);
}