Kod:
private void button1_Click(object sender, EventArgs e)
{
if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox3.Text != ""))
{
baglanti.Open();
//string sorgu = "insert into ogrenciler(OkulNo,Ad,Soyad,Resim) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + pictureBox1 .ImageLocation + "')";
string sorgu = "select OkulNo from ogrenciler where OkulNo=@da";
OleDbCommand komut = new OleDbCommand(sorgu, baglanti);
komut.Parameters.AddWithValue("@da", textBox1.Text);
OleDbDataReader dr = komut.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("Aynı kaydı tekrar ekleyemezsiniz");
komut.ExecuteNonQuery();
baglanti.Close();
}
else
{
string sorgum = "insert into ogrenciler(OkulNo,Ad,Soyad,Resim) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + pictureBox1.ImageLocation + "')";
OleDbCommand komut2 = new OleDbCommand(sorgum, baglanti);
komut2.ExecuteNonQuery();
pictureBox1.Image.Save("Resimler/" + textBox1.Text.ToString () + ".jpg");
baglanti.Close();
TabloyuDoldur();
MessageBox.Show("kayıt eklendi");
}
}
}