NPGSQL好像有一个比较大的bug?

发布于 2024-09-02 09:58:06 字数 386 浏览 3 评论 0原文

这是一个奇怪的问题,当我运行以下代码时,所有行都从数据库返回。想象一下如果这是更新或删除会发生什么。

    Dim cmd As New NpgsqlCommand

    cmd.Connection = conn
    cmd.CommandText = "select * FROM ac_profiles WHERE profileid = @profileId"
    cmd.Parameters.Add("@profile", 58)
    Dim dt As DataTable = DataAccess2.DataAccess.sqlQueryDb(cmd)

    DataGridView1.DataSource = dt

我的问题是为什么会发生这种情况?

this is a weird one, when I run the following code all rows are returned from the db. Imagaine what would happen if this was an update or delete.

    Dim cmd As New NpgsqlCommand

    cmd.Connection = conn
    cmd.CommandText = "select * FROM ac_profiles WHERE profileid = @profileId"
    cmd.Parameters.Add("@profile", 58)
    Dim dt As DataTable = DataAccess2.DataAccess.sqlQueryDb(cmd)

    DataGridView1.DataSource = dt

My question is why is this happening?

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

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

发布评论

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

评论(1

枕花眠 2024-09-09 09:58:06

我不是 pg-sql 专家,但我强烈怀疑这是因为您添加了与 SQL 语句中使用的参数不同的参数。我认为您还使用了错误的语法来引用参数。有关详细信息,请参阅用户手册。试试这个:

cmd.Connection = conn
cmd.CommandText = "select * FROM ac_profiles WHERE profileid = :profileid"
cmd.Parameters.Add("profileid", 58)
Dim dt As DataTable = DataAccess2.DataAccess.sqlQueryDb(cmd)

I'm no pg-sql expert, but I strongly suspect it's because you're adding a different parameter from the one you're using in the SQL statement. I think you're also using the wrong syntax to refer to a parameter. See the user manual for more information. Try this:

cmd.Connection = conn
cmd.CommandText = "select * FROM ac_profiles WHERE profileid = :profileid"
cmd.Parameters.Add("profileid", 58)
Dim dt As DataTable = DataAccess2.DataAccess.sqlQueryDb(cmd)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文