程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了位置 0 Vb.net 和 Mysql 没有行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决位置 0 Vb.net 和 Mysql 没有行?

开发过程中遇到位置 0 Vb.net 和 Mysql 没有行的问题如何解决?下面主要结合日常开发的经验,给出你关于位置 0 Vb.net 和 Mysql 没有行的解决方法建议,希望对你解决位置 0 Vb.net 和 Mysql 没有行有所启发或帮助;

我正在尝试从表“打印机”上的“状态”行获取和打印数据,但它一直说“位置 0 处没有行。”

 Dim conn As New deepconnection()
    Dim adapter As New MysqLDataAdapter()
    Dim table As New Datatable()
    Dim ds,ds1 As New DataSet
    Dim command As New MysqLCommand("SELECT * FROM printer",conn.getConnection)
    conn.openOcean()
    PrinterStatus.Text = table.Rows(0).Item("status")

连接:

 Private fishcatch As New MysqLConnection("datasource=localhost;port=3306;username=root;password=xxxxx;database=deep_ocean")

' Get the connection only to read
Readonly Property getConnection() As MysqLConnection
    Get
        Return fishcatch
    End Get
End Property

打开连接:

Sub openOcean()
    If fishcatch.State = ConnectionState.Closed Then
        fishcatch.open()
    End If
End Sub

怎么了?

解决方法

@H_607_24@

您尚未执行填充表格的命令。没有那部分,桌子仍然是空的

Dim command As New MySqlCommand("SELECT * FROM printer",conn.getConnection)
conn.openOcean()

' Execute the command and pass the reader to the table load method
table.Load(command.ExecuteReader())

PrinterStatus.Text = table.Rows(0).Item("status")

即使在此之后,如果名为 Printer 的数据库表中没有记录,该表仍可能为空,因此在从数据表中读取任何内容之前,请始终检查行数

If table.Rows.Count > 0 Then
    PrinterStatus.Text = table.Rows(0).Item("status")
    ...
End If

大佬总结

以上是大佬教程为你收集整理的位置 0 Vb.net 和 Mysql 没有行全部内容,希望文章能够帮你解决位置 0 Vb.net 和 Mysql 没有行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。