【问题标题】:error in conversion from string to integer从字符串到整数的转换错误
【发布时间】:2016-06-08 08:08:48
【问题描述】:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ListBox1.Items.Clear()

    sql = "SELECT * FROM testing_mysql_vb"
    Try
        dbcomm = New MySqlCommand(sql, dbconn)
        dbread = dbcomm.ExecuteReader()

        While dbread.Read
            ListBox1.Items.Add(dbread("product_name")("product_quantity"))
        End While

        dbread.Close()
    Catch ex As Exception
        MsgBox("Error in collecting data from Database. Error is :" & ex.Message)
        dbread.Close()
        Exit Sub
    End Try
End Sub
End Class

我无法从我的数据库中获取数据。

它说从字符串转换为整数时出错。

【问题讨论】:

    标签: mysql vb.net xampp


    【解决方案1】:

    您将dbread("product_name")("product_quantity") 传递给ListBox.Items.Add。那是行不通的。也许您想合并这两列:

    Dim prodNameVal As Object = dbread("product_name")
    Dim productQuantityValue As Object = dbread("product_quantity")
    ListBox1.Items.Add(String.Format("{0}: {1}", prodNameVal, productQuantityValue))
    

    【讨论】:

      【解决方案2】:

      如果你的数据库给你一个整数作为返回值,你需要把它放在一个只接受字符串的地方(一个控件或 response.write),你可以使用。 toString()

      【讨论】:

        【解决方案3】:

        我假设产品数量是一个整数,你需要一个字符串,如果是这样,你可以这样修复它。

        改变

        ListBox1.Items.Add(dbread("product_name")("product_quantity"))
        

           ListBox1.Items.Add(dbread("product_name") & ("product_quantity").tostring())
        

         ListBox1.Items.Add(dbread("product_name") & Cstr(("product_quantity")))
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多