【问题标题】:OleDB Data not reading from the correct rowOleDB 数据未从正确的行读取
【发布时间】:2012-02-05 05:33:24
【问题描述】:

我创建了以下方法,以前 stock1Label 到 stock3Label 能够从数据库中输出正确的值,但是在我向 ProductsTable 添加更多行后,source.Rows[0][0]、[1][0]等似乎是从我的表的第 8 行而不是第 1 行获取值,有人知道为什么会这样吗?

    private void UpdateStocks()
    {
        string query = "SELECT pQty FROM ProductsTable";
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, DBconn);
        DataTable source = new DataTable();
        dAdapter.Fill(source);
        stock1Label.Text = source.Rows[0][0].ToString();
        stock2Label.Text = source.Rows[1][0].ToString();
        stock3Label.Text = source.Rows[2][0].ToString();
        stock4Label.Text = source.Rows[3][0].ToString();
        stock5Label.Text = source.Rows[4][0].ToString();
        stock6Label.Text = source.Rows[5][0].ToString();
    }

【问题讨论】:

    标签: c# ms-access oledb


    【解决方案1】:

    大多数(全部?)数据库系统没有定义顺序。
    您将收到非确定存储顺序的行,而不是您插入它们的顺序。

    要获得有意义的一致排序,您需要添加一个ORDER BY 子句。

    【讨论】:

      猜你喜欢
      • 2015-07-25
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      相关资源
      最近更新 更多