Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi here is the code I wrote. there is no error at my connection and my database is filled with data which I want to take but I cant get "Urunler.isim" datas I always get "No data exists for the row/column" error message at my sSQL2 code thanks already for your help Smile | :) .
 
 class urunadapter
    {
        public void urungetir(string firma , ComboBox cmburun) 
        {
            companymodel.cnvt conn = new companymodel.cnvt();
            conn.baglan();
            DataSet dt = new DataSet();
            
            string sSQL = "SELECT * FROM Firmalar WHERE Firmalar.isim='" + firma + "'";
            OleDbCommand komut = new OleDbCommand(sSQL,conn.baglanti);
            OleDbDataReader oku = komut.ExecuteReader();
            
            
            string sSQL2 = "SELECT Urunler.isim FROM Urunler WHERE Firmalar.FirmaID="+oku["FirmaID"]+"";
            komut = new OleDbCommand(sSQL2,conn.baglanti);
            OleDbDataAdapter adp = new OleDbDataAdapter(komut);
            adp.Fill(dt, "Urunler");
            cmburun.Items.Add("Seçiniz");
            cmburun.SelectedIndex = 0;
            foreach (DataRow listele in dt.Tables["Urunler"].Rows)
            {
                string satir = listele[0].ToString();
                bool durum = cmburun.Items.Contains(satir);
                if(!durum)
                {
                    cmburun.Items.Add(satir).ToString();
                }
            }
            conn.bkes();
Posted 31-Dec-10 21:20pm
Beytul392

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Since you are using DataReader , The default position of the OledbDataReader is before the first record. Therefore, you must call Read to begin accessing any data.
You should Call
//Call Read method on oku before accessing data.
OleDbDataReader oku = komut.ExecuteReader();
while (oku.Read()) 
{
 // Access record of oku in loop , if you are suppoosed to get zero or more than one record

}            
 
oku.Read() will return false in case no record exists, so you should always evaluate oku.Read() before accessing any data either using If or While or whatever you like.
  Permalink  
v2
Comments
Manfred R. Bihy at 1-Jan-11 12:14pm
   
Good call! 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 1 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100