[英]There is no row at position 0 Vb.net and 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
怎么了?
您尚未执行填充表的命令。 没有那部分,桌子仍然是空的
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.