Reputation: 11
I been used this code just fine in another table but in this one, I can't use it because of this error. I can't figure out the problem. I need your help. This is what my database looks like:
And this is the design of the database. Translation of data types are:
Auto number
Number
short text
short text
short text
Number
private void button_degistir_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value);
OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= hasta_bilgisi.accdb");
baglanti.Open();
OleDbCommand guncelle_komut = new OleDbCommand("update tbl_Randevu set randevu_hasta_id=@hastaninid,teşhis=@teshis,tedavi=@tedav,randevu_tarihi=@randevu_tarih,verilen_ilaç_id=@ilacid where randevu_hasta_id=@x", baglanti);
guncelle_komut.Parameters.AddWithValue("@hastaninid", textBox_hastaid.Text);
guncelle_komut.Parameters.AddWithValue("@teshis", textBox_teshis.Text);
guncelle_komut.Parameters.AddWithValue("@tedav", textBox_tedavi.Text);
guncelle_komut.Parameters.AddWithValue("@randevu_tarih", dateTimePicker1.Value.ToString());
guncelle_komut.Parameters.AddWithValue("@ilacid", comboBox_ilac.SelectedIndex.ToString());
MessageBox.Show(guncelle_komut.ExecuteNonQuery() + "adet güncellendi");
baglanti.Close();
}
Upvotes: 0
Views: 62
Reputation: 94
For the error, you forgot to add the id parameter;
guncelle_komut.Parameters.AddWithValue("@x", id);
But it seems there is one more problem if I understand your code & table design correctly. You're using randevu_hasta_id for the id
parameter which is @x
. But that's not a unique id. It's a recurring field. If you use randevu_hasta_id
, all rows that have the same randevu_hasta_id
will be updated. Not just one. Your unique id is randevu_id
. You should use that field if you want to update one specific row.
Upvotes: 1