• 16-01-2011, 05:41:02
    #1
    Şimdi yapmak istediğim şey şu:
    e-okul uygulaması yapıyorum csharp ta ama öğrenci girişi kısmında öğrenci numarasını yazıp girip notlarına sorunsuz bakıyor ama yanlış bi numara girince hata vermiyo boş textboxlar geliyo bunu nasıl düzeltiriz?



               try
                {
                    int bul;
                    bul = int.Parse(textBox1.Text);
                    OleDbCommand ara = new OleDbCommand("Select * from tablo1 where num = " + bul + "", baglanti);
                    OleDbDataReader oku = null;
                    baglanti.Open();
                    oku = ara.ExecuteReader();
                    while (oku.Read())
                    {
                        ListViewItem kayit = new ListViewItem(oku["num"].ToString());
                        label4.Text = oku["num"].ToString();
                        label5.Text = oku["sinif"].ToString();
                        textBox4.Text = oku["y1"].ToString();
                        textBox5.Text = oku["y2"].ToString();
                        textBox6.Text = oku["s1"].ToString();
                        textBox7.Text = oku["ort"].ToString();
                        label2.Text = oku["ad"].ToString();
                        label3.Text = oku["soy"].ToString();
                        double ort = Convert.ToDouble(oku["ort"]);
                        if (ort > 45)
                            textBox8.Text = "Geçti";
                        else if (ort < 45)
                            textBox8.Text = "Kaldı";
                    }
                    oku.Close();
                    baglanti.Close();
                }
    
    
               
               catch
                {
    
                    MessageBox.Show("Böyle bi öğrenci Yok");
                    Form1 frm1 = new Form1();
                    this.Hide();
                    frm1.Show();
                }
  • 16-01-2011, 06:21:55
    #2
    http://msdn.microsoft.com/en-us/library/13940fs2.aspx
    hata mesajindan sonra yeni form objesi olusturmak yerine bu fonksiyonu kullanip basa don. (ilk basladigin yere bir label eklemek gerek tabii ki)
  • 16-01-2011, 06:39:08
    #3
    Yaptığın şeyde mantık hatan var.
    Buyur bu şekilde yap.

    Alıntı
    try
    {
    int bul;
    bul = int.Parse(textBox1.Text);
    OleDbCommand ara = new OleDbCommand("Select * from tablo1 where num = " + bul + "", baglanti);
    OleDbDataReader oku = null;
    baglanti.Open();
    oku = ara.ExecuteReader();
    if (!oku.HasRows)
    {
    while (oku.Read())
    {
    ListViewItem kayit = new ListViewItem(oku["num"].ToString());
    label4.Text = oku["num"].ToString();
    label5.Text = oku["sinif"].ToString();
    textBox4.Text = oku["y1"].ToString();
    textBox5.Text = oku["y2"].ToString();
    textBox6.Text = oku["s1"].ToString();
    textBox7.Text = oku["ort"].ToString();
    label2.Text = oku["ad"].ToString();
    label3.Text = oku["soy"].ToString();
    double ort = Convert.ToDouble(oku["ort"]);
    if (ort > 45)
    textBox8.Text = "Geçti";
    else if (ort < 45)
    textBox8.Text = "Kaldı";
    }
    }
    else {
    MessageBox.Show("Böyle bir öğrenci yok!");
    }
    oku.Close();
    baglanti.Close();
    }
    catch (Exception e)
    {

    MessageBox.Show("Hata Oluştu");

    }
  • 16-01-2011, 11:40:58
    #4
    Meksikalı adlı üyeden alıntı: mesajı görüntüle
    Yaptığın şeyde mantık hatan var.
    Buyur bu şekilde yap.
    Error	1	A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else

    "Exception e" burda hata var diyo
  • 16-01-2011, 11:49:01
    #5
    Eposta Aktivasyonu Gerekmekte
    DataReader'ın HasRows özelliği kayıt olup olmadığını dönderir bool tipinde.
    ona göre işlem yapabilirsin.

    if(oku.HasRows)
    //Kayıt var
    else throw new Exception('Kayıt yok hata fırlat');
  • 16-01-2011, 16:14:50
    #6
    Assasin adlı üyeden alıntı: mesajı görüntüle
    Error    1    A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else

    "Exception e" burda hata var diyo
     
     
    try
    {
    int bul;
    bul = int.Parse(textBox1.Text);
    OleDbCommand ara = new OleDbCommand("Select * from tablo1 where num = " + bul + "", baglanti);
    OleDbDataReader oku = null;
    baglanti.Open();
    oku = ara.ExecuteReader();
    if (!oku.HasRows)
    {
    while (oku.Read())
    {
    ListViewItem kayit = new ListViewItem(oku["num"].ToString());
    label4.Text = oku["num"].ToString();
    label5.Text = oku["sinif"].ToString();
    textBox4.Text = oku["y1"].ToString();
    textBox5.Text = oku["y2"].ToString();
    textBox6.Text = oku["s1"].ToString();
    textBox7.Text = oku["ort"].ToString();
    label2.Text = oku["ad"].ToString();
    label3.Text = oku["soy"].ToString();
    double ort = Convert.ToDouble(oku["ort"]);
    if (ort > 45)
    textBox8.Text = "Geçti";
    else if (ort < 45)
    textBox8.Text = "Kaldı";
    }
    }
    else {
    MessageBox.Show("Böyle bir öğrenci yok!");
    }
    oku.Close();
    baglanti.Close();
    }
    catch{
    
    MessageBox.Show("Hata Oluştu");
    
    }