0

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:

enter image description here

And this is the design of the database. Translation of data types are:

Auto number
Number
short text
short text
short text
Number

enter image description here

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();
}
0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you you were right. I fixed the issue thank you mimozz
No problem & have a nice one Yakup =) And RBT, thanks for the edit and the nice example about readability =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.