使用listview显示错误消息绑定数据库 [英] display error message binding database with listview
本文介绍了使用listview显示错误消息绑定数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我绑定列表视图时显示错误,例如无法将类型为"System.Decimal"的对象转换为类型为"System.String"."
while i am binding listview display error like "Unable to cast object of type ''System.Decimal'' to type ''System.String''."
Imports System.Data.SqlClient
Public Class ListViewData
Public Sub FillListView(ByRef MyListView As ListView, _
ByRef myData As SqlDataReader)
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim strTest As String
Dim shtCntr As Short
MyListView.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
lvwColumn = New ColumnHeader()
lvwColumn.Text = myData.GetName(shtCntr)
MyListView.Columns.Add(lvwColumn)
Next
Do While myData.Read
itmListItem = New ListViewItem()
strTest = IIf(myData.IsDBNull(0), "", myData.GetString(0))
itmListItem.Text = strTest
For shtCntr = 1 To myData.FieldCount() - 1
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetString(shtCntr))
End If
Next shtCntr
MyListView.Items.Add(itmListItem)
Loop
End Sub
End Class
推荐答案
错误不言自明.该代码为字符串变量分配了一个小数.
调试,找到错误的地方.在将小数点分配给字符串之前,请使用十进制值类型的toString()
或Convert.ToString()
方法.
如果不打算使用字符串,则使用适当的变量声明.
您是否希望有人在这里重写您的代码以解决简单的错误?
The error is self explanatory. The code assigns a decimal to a string variable.
Debug, find the error place. Use thetoString()
of the decimal value type orConvert.ToString()
method before assign the decimal to string.
If you are not intended to use a string then use appropriate variable declaration.
Do you want someone here rewrite your code for a simple bug?
这篇关于使用listview显示错误消息绑定数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文