winforms 内部联接查询时列表框项System.Data.DataRowView

y1aodyip  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(185)

here is two of my 'Ders' items(bottom listbox)它得到了项目,但我不能显示它们,两个输出应该来自查询,所以查询是正确的。一定是在DisplayMember中出错了,但我不能弄清楚它2个小时。
here is the data that i receive from query
这是我代码

private void kryptonListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            bolumsilbutton.Enabled = true;
            bolumuduzenlebutton.Enabled = true;
            bolumupbutton.Enabled = true;
            bolumdownbutton.Enabled = true;
            derseklebutton.Enabled = true;
            derslistbox.Enabled = true;

            if (Connection.DBPath == null)
            {
                //burada bölüm ismine göre veri çekilecek(veritabanı olmadan!)

            }
            else
            {
                try
                {
                    OleDbConnection con = new OleDbConnection();
                    string query;
                    con = Connection.GetConnection();
                    con.Open();

                    query = "SELECT Ders.ders_id, Ders.ders_ismi FROM Ders INNER JOIN (Bölüm INNER JOIN Bölüm_ders ON Bölüm.bolum_id = Bölüm_ders.bolum_id.Value) ON Ders.ders_id = Bölüm_ders.ders_id WHERE (((Bölüm.bolum_id)=" + bolumlerlistbox.SelectedValue.ToString() + "))";
                    OleDbDataAdapter da = new OleDbDataAdapter(query, con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "Ders");
                    Connection.bolumlerform.derslistbox.DisplayMember = "Ders.ders_ismi";
                    Connection.bolumlerform.derslistbox.ValueMember = "Ders.ders_id";
                    Connection.bolumlerform.derslistbox.DataSource = ds.Tables["Ders"];



                    con.Close();

                }
                catch (OleDbException ex)
                {
                    MessageBox.Show("Veritabanına bağlanırken hata oluştu !" + ex.Message);
                }
            }


        }
os8fio9y

os8fio9y1#

如果有人找不到解决方案,我已经找到了。我已经将查询更改为
SELECT Ders.ders_id, Ders.ders_ismi FROM...到这个
SELECT Ders.ders_id as ders_id, Ders.ders_ismi as ders_ismi FROM ...
当然也将显示构件和值构件改为这样
Connection.bolumlerform.derslistbox.DisplayMember = "ders_ismi"; Connection.bolumlerform.derslistbox.ValueMember = "ders_id";

相关问题