我想在Labels
中动态创建TextBoxes
和Form
。
Label
中的文本应来自我的SQL Compact
数据库。
运行Form
时,出现以下错误:
从字符串“”转换为“ double”类型无效。
我已经尝试过研究,但是找不到答案。
谢谢
这是我的代码:
Public Function countrows()
checkServer()
CnString = "Data Source=|DataDirectory|\dbEsyPOS.sdf;Persist Security Info=True; Password=CQ25dbEsyPOS"
Dim sqlCon As New SqlCeConnection(CnString)
sqlCon.Open()
Using cmd As New SqlCeCommand("SELECT *FROM tbl_sale ")
Using sda As New SqlCeDataAdapter
cmd.Connection = sqlCon
sda.SelectCommand = cmd
Using sqlDT As New DataTable
Try
sda.Fill(sqlDT)
If (sqlDT.Rows.Count > 0) Then
For i As Integer = 0 To sqlDT.Rows.Count - 1
Dim lblTitle As Label = New Label()
lblTitle.Name = "Label" & i.ToString()
lblTitle.Text = CStr(sqlDT.Rows(i)(0)("term_of_payment"))
Panel2.Controls.Add(lblTitle)
Next
End If
Catch ex As Exception
MessageBox.Show("Oops :" + ex.Message)
End Try
End Using
End Using
End Using
End Function
请注意,我是新手,不胜感激:)
答案 0 :(得分:0)
这行代码没有意义:
lblTitle.Text = CnString(sqlDT.Rows(i)(0)("term_of_payment"))
我猜您实际上要执行的操作是从'term_of_payment'列中获取String
。看起来像这样:
lblTitle.Text = CStr(sqlDT.Rows(i)("term_of_payment"))