0

我的数据库中有 2 列,表单中有 2 个 ComboBox,它们相互连接。一个包含浮点值,另一个包含 VarChar。我使用下面的代码,它适用于带有 VarChar 的代码,但不适用于带有 float 的代码。怎么了?

sqlstr = "SELECT * FROM Student WHERE Code = 2"
DBCmd = New MySql.Data.MySqlClient.MySqlCommand(sqlstr, DBConn)
DBDr = DBCmd.ExecuteReader

While (DBDr.Read())
CBox_TBand.SelectedItem = DBDr("TB")
CBox_State.SelectedItem = DBDr("State")
End While
DBCmd.Dispose()
DBDr.Close()

TB 列包含浮点数,State 列包含 Varchar。

4

1 回答 1

0

Its possible you are losing formatting when converting from DB's Float to String. Try this:

CBox_TBand.SelectedItem = Decimal.Parse(DBDr("TB")).ToString()
于 2013-04-01T19:48:37.830 回答