如果SQL查询为空,则关闭表单

时间:2014-07-12 21:43:51

标签: mysql vb.net

我有一个表格,用sql查询来结束正在进行的操作,它只会显示组合框中正在进行的操作。如果没有正在进行的操作,程序崩溃!我如何防止它崩溃?

Public conexao As New MySqlConnection
Public comando As New MySqlCommand
Public result As MySqlDataReader
Public r3 As MySqlDataReader
Public bs As BindingSource = New BindingSource()
Public strsql As String

Private Sub editarops_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Enabled = True
    conexao.ConnectionString = "server = localhost; user =root; database = frota;"
    conexao.Open()
    comando.Connection = conexao
    strsql = "SELECT codtrab, carga, origem, destino, estado, dataini FROM trabalhos "
    comando.Connection = conexao
    strsql = "SELECT codtrab, carga, origem, destino, estado, dataini FROM trabalhos "
        r3 = comando.ExecuteReader
        bs.DataSource = r3
        ComboBox1.Text = bs.Current(0)
        tboxfunc.Text = bs.Current(1)
        TextBox1.Text = bs.Current(2)
        TextBox2.Text = bs.Current(3)
        TextBox3.Text = bs.Current(5)
        Atualizar.Enabled = True
        Cancelar.Enabled = True
        r3.Close()

        Dim sStmt1 As String = "Select codtrab from trabalhos where estado = 'En Route' "
        Dim cmd1 As New MySqlCommand(sStmt1, conexao)
        Dim da1 As MySqlDataAdapter = New MySqlDataAdapter(cmd1)
        Dim dt1 As New DataTable("trabalhos")
        da1.Fill(dt1)

        ComboBox1.DataSource = dt1
        ComboBox1.DisplayMember = "codtrab"
        da1.Dispose()
        repor()
        TextBox1.Enabled = False
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        TextBox5.Enabled = False
        TextBox6.Enabled = False
        tboxfunc.Enabled = False
End Sub

0 个答案:

没有答案