尝试转换为int32时,字符串格式错误

时间:2015-12-28 20:37:31

标签: int format

我尝试将我的WPF应用程序中的字符串转换为int,但内容为" 5",但是得到错误"输入字符串格式错误"。我已经尝试过Convert.ToInt32和Int32.Parse方法,但都失败了。这是代码:

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            Dim Conexion As New MySql.Data.MySqlClient.MySqlConnection
            Dim CadenaSQL As String = "SELECT * FROM Alumnos ORDER BY nombre"
            Dim CadenaConexion As String = "Data Source=localhost;" & _
                                           "Database=" & "NuevaBD" & ";" & _
                                           "User Id=root;Password="
            Dim Comando As New MySql.Data.MySqlClient.MySqlCommand(CadenaSQL)
            Conexion = New MySql.Data.MySqlClient.MySqlConnection(CadenaConexion)

            Try
                Dim conjuntoDatos As New DataSet()
            Conexion.Open()
            'here dataset i dont know how it
            'Comando.Fill(conjuntoDatos, "Alumnos")
            Conexion.Close()

            Dim tabla As DataTable
            tabla = conjuntoDatos.Tables("Alumnos")
            Dim fila As DataRow
            Me.ListaAlumnos.Items.Clear()
            For Each fila In tabla.Rows
                ' Muestra los datos en un ListBox
                Me.ListaAlumnos.Items.Add(fila.Item("Nombre") & " " & fila.Item("Apellidos"))
            Next
        Catch ex As MySql.Data.MySqlClient.MySqlException
            MsgBox("No se ha podido establecer " & vbCrLf & _
                      "la conexión con la base de datos.", MsgBoxStyle.Critical)
        Finally

            Select Case Conexion.State
                Case ConnectionState.Open
                    Conexion.Close()
            End Select
        End Try
    End Sub

我真的不明白这一点,因为它在办公室电脑上工作正常......

1 个答案:

答案 0 :(得分:0)

抱歉,我没有正确设置调试器。代码很好。