无法从数据库获取数据“行/列不存在数据" [英] Can't get data from database "No data exists for the row/column"

查看:206
本文介绍了无法从数据库获取数据“行/列不存在数据"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编写的代码.在我的连接处没有错误,并且我的数据库中充满了我想获取的数据,但是我无法获得"Urunler.isim"数据我的sSQL2代码始终收到行/列没有数据"错误消息,这已经非常感谢为您提供帮助:).

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 :) .

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

推荐答案

由于您正在使用DataReader,因此OledbDataReader的默认位置在第一条记录之前.因此,您必须调用Read才能开始访问任何数据.
你应该打电话给
在访问数据之前,
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()将返回false,因此,在使用If或While或任何您喜欢的数据访问任何数据之前,您应该始终评估oku.Read().



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.


这篇关于无法从数据库获取数据“行/列不存在数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆