MySQL Bug - 在调用read()之前无效尝试访问字段

时间:2014-04-06 03:17:08

标签: mysql vb.net

我到处搜索,我仍然无法弄清楚这一点。每次打开表单时都会出现此错误,但程序会一直运行而没有任何问题。我已经发现错误是因为我在程序中添加了一个功能。当我从组合框中选择车辆ID代码时,文本框会自动显示车辆名称。这是错误的起源。

Private Sub ComboBox1_SelectedIndexChanged(sender as Object,e As EventArgs)处理ComboBox1.SelectedIndexChanged

    Try
        strsql = "SELECT nome FROM funcionarios where codfunc = " & Val(ComboBox1.Text) & ""
        comando.CommandText = strsql
        result = comando.ExecuteReader
        bs.DataSource = result
        tboxfunc.Text = bs.Current(0)
    Catch erro As MySqlException
        MessageBox.Show(erro.Message, "Erro do MySQL:",
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Catch erro As Exception
        MessageBox.Show(erro.Message, "Erro da Aplicação:",
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    End Try
    result.Close()
End Sub

0 个答案:

没有答案