将数据加载到vb.net 2008和sql 2005中的listview中 [英] Loading data into a listview in vb.net 2008 and sql 2005

查看:66
本文介绍了将数据加载到vb.net 2008和sql 2005中的listview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子



 [动员]  - 主要关键是[Fen_Inovoice_No]它是[invovoice]的forgien键详情] 

[发票详情]主键是[Fen_Inovoice_No],[Item]



当我试图查看数据,所有数据都没有加载到listview为什么会这样?只加载一行





  private   Sub  viewItem1( ByVal  invoice_no  As  字符串

myConnection = SqlConnection(connectionstring)
myConnection.Open()

sqlcmd = SqlCommand( 选择项目,数量,描述,金额来自[发票详情]其中Fen_Inovoice_No ='& invoice_no& < span class =code-string>',myConnection)

sqlcmd.ExecuteNonQuery()

' Dim dr As SqlDataReader = myCommand1.ExecuteReader
Dim dr As SqlDataReader = sqlcmd.ExecuteReader

dr.Read()
' pr = dr1(Category)。ToString

''' < span class =code-comment>''''''''''
' For i = 0 To TempData.Rows.Count-1
Dim newItem1 < span class =code-keyword>作为 ListViewItem(dr.Item( Item)。ToString)
newItem1.SubItems.Add(dr( Descrption)。ToString)
newItem1.SubItems.Add(dr( Quantity))
newItem1.SubItems.Add(dr( Amo unt))
ListView1.Items.Add(newItem1)
' newItem .SubItems.Add()

CalTotal()
dr.Close()
''' '''''''''''
myConnection.Close()

结束 Sub


私有 Sub CalTotal()
Dim TotalSum As Double = 0
Dim TempNode As ListViewItem
Dim TempDbl As Double
For 每个 TempNode ListView1.Items
如果 Double .TryParse(TempNode.SubItems.Item( 3 )。Text,TempDbl)然后

结束 如果
TotalSum + = TempDbl
下一步

TextBox11.Text = TotalSum

结束 Sub

解决方案

< blockquote>我想你应该把一行代码放到listview:

  dr。 read()
Dim newItem1 As New ListViewItem(dr.Item( Item)。ToString)
newItem1.SubItems.Add(dr( Descrption)。ToString)
newItem1.SubItems.Add(dr( 数量))
newItem1.SubItems.Add(dr( 金额))
ListView1.Items.Add(newItem1)



wend


I have two tables

[Mobilization]-Primary key is [Fen_Inovoice_No] it is the forgien key is of [invovoice details]

[invovoice details] the primary keys are [Fen_Inovoice_No],[Item]


when I tried to view the data , the all data are not loading to listview why is that? only a one row is load


private Sub viewItem1(ByVal invoice_no As String)

    myConnection = New SqlConnection(connectionstring)
    myConnection.Open()

    sqlcmd = New SqlCommand("SELECT Item,Quantity,Descrption ,Amount FROM [invovoice details] where  Fen_Inovoice_No='" & invoice_no & "'   ", myConnection)

    sqlcmd.ExecuteNonQuery()

    '    Dim dr As SqlDataReader = myCommand1.ExecuteReader
    Dim dr As SqlDataReader = sqlcmd.ExecuteReader

    dr.Read()
    ' pr = dr1("Category").ToString

    ''''''''''''''''''''''''
    ' For i = 0 To TempData.Rows.Count-1
    Dim newItem1 As New ListViewItem(dr.Item("Item").ToString)
    newItem1.SubItems.Add(dr("Descrption").ToString)
    newItem1.SubItems.Add(dr("Quantity"))
    newItem1.SubItems.Add(dr("Amount"))
    ListView1.Items.Add(newItem1)
    ' newItem.SubItems.Add()

    CalTotal()
    dr.Close()
    '''''''''''''''''''''''''''''
    myConnection.Close()

End Sub


Private Sub CalTotal()
    Dim TotalSum As Double = 0
    Dim TempNode As ListViewItem
    Dim TempDbl As Double
    For Each TempNode In ListView1.Items
        If Double.TryParse(TempNode.SubItems.Item(3).Text, TempDbl) Then

        End If
        TotalSum += TempDbl
    Next

    TextBox11.Text = TotalSum

End Sub

解决方案

i think u should put a code like this when a row to listview:

while dr.read()
     Dim newItem1 As New ListViewItem(dr.Item("Item").ToString)
     newItem1.SubItems.Add(dr("Descrption").ToString)
     newItem1.SubItems.Add(dr("Quantity"))
     newItem1.SubItems.Add(dr("Amount"))
     ListView1.Items.Add(newItem1)


wend


这篇关于将数据加载到vb.net 2008和sql 2005中的listview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆