OleDB 数据未从正确的行读取

发布于 2025-01-02 08:55:20 字数 772 浏览 6 评论 0原文

我创建了以下方法,之前 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();
    }

I have the following method created and previously stock1Label to stock3Label were able to output the correct values from the database however after i added more rows to my ProductsTable, source.Rows[0][0], [1][0], etc. seems to be taking values from row 8 onwards of my table instead of row 1, anyone know why this is happening?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2025-01-09 08:55:20

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

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

Most (all?) database systems do not have defined orders.
You will receive rows in non-determinstic storage order, not in the order you inserted them.

To receive a meaningful consistent ordering, you need to add an ORDER BY clause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文