0

Hello
Teachers
I create a project in vb.net 2010 with access database. I want to show data in listview. It Is show in listview but a problem I entry Id wise. So, when I click on the show data button I see the Id . How to show the id wise actual data.

I use the code for data load in listview1

Public Sub Displayitem()
        ListView1.Items.Clear()
        Dim cmd As New OleDb.OleDbCommand("SELECT * FROM pur_inv ORDER BY purinvdt", cn)
        Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()

        Do While dr.Read()
            Dim new_item As New  _
     ListViewItem(dr.Item("purinvdt").ToString)
            new_item.SubItems.Add(dr.Item("purinvid").ToString)
            new_item.SubItems.Add(dr.Item("prtid").ToString)

            new_item.SubItems.Add(dr.Item("invtypid").ToString)
            new_item.SubItems.Add(dr.Item("taxamt").ToString)
            new_item.SubItems.Add(dr.Item("tottaxblamt").ToString)
            new_item.SubItems.Add(dr.Item("invamt").ToString)
            ListView1.Items.Add(new_item)
        Loop
    End Sub

Edited by Jayanta_1

Attachments inv_type.PNG 10.7 KB purchase_inv.PNG 62.37 KB inv_type.PNG 10.7 KB listview1.PNG 49.14 KB party_name.PNG 10.73 KB
2
Contributors
11
Replies
57
Views
2 Weeks
Discussion Span
Last Post by xrj
0

I can't see anything wrong with the code you are sharing. So, what's the problem? Can you explain a bit further?

0

"Inv. Type" column in listview show the number(id of invoice type 2,3...) but I want to see here invoice type means (u002 or u003 .......)

Attachments listview1001.png 56.78 KB
0

If you mean to select a concrete id, you could do the following. When invtypid is -1, all the ids will be shown (on load event); when > -1 that only id will be shown (when button is clicked):

    Public Sub Displayitem(Optional invtypid As Int32 = -1)

        Dim da As New OleDbDataAdapter("SELECT * FROM pur_inv ORDER BY purinvdt", cn)
        Dim ds As New DataSet
        da.Fill(ds, "myTable")
        Dim dt As DataTable = ds.Tables("myTable")

        Dim q() As DataRow
        If invtypid = -1 Then
            q = (From r In dt.AsEnumerable Select r).ToArray
        Else
            q = (From r In dt.AsEnumerable _
                 Where r.Item("invtypid") = invtypid _
                 Select r).ToArray
        End If

        ListView1.Items.Clear()
        For Each dr As DataRow In q
            Dim new_item As New  _
                 ListViewItem(dr.Item("purinvdt").ToString)
            new_item.SubItems.Add(dr.Item("purinvid").ToString)
            new_item.SubItems.Add(dr.Item("prtid").ToString)

            new_item.SubItems.Add(dr.Item("invtypid").ToString)
            new_item.SubItems.Add(dr.Item("taxamt").ToString)
            new_item.SubItems.Add(dr.Item("tottaxblamt").ToString)
            new_item.SubItems.Add(dr.Item("invamt").ToString)
            ListView1.Items.Add(new_item)
        Next
    End Sub
0

it is show same result
in inv type column show the inv type not inv id

in the column where show the "2" in this place show "U002"

0

Then change invtypid by invtyp:

Public Sub Displayitem()
        ListView1.Items.Clear()
        Dim cmd As New OleDb.OleDbCommand("SELECT * FROM pur_inv ORDER BY purinvdt", cn)
        Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()

        Do While dr.Read()
            Dim new_item As New  _
     ListViewItem(dr.Item("purinvdt").ToString)
            new_item.SubItems.Add(dr.Item("purinvid").ToString)
            new_item.SubItems.Add(dr.Item("prtid").ToString)

            new_item.SubItems.Add(dr.Item("invtyp").ToString)
            new_item.SubItems.Add(dr.Item("taxamt").ToString)
            new_item.SubItems.Add(dr.Item("tottaxblamt").ToString)
            new_item.SubItems.Add(dr.Item("invamt").ToString)
            ListView1.Items.Add(new_item)
        Loop
    End Sub
0

Then change invtypid by invtyp:

invtyp field not avalable in the table pur_inv.

it is differant table (name: inv_type, here two column a> invtypid b> invtyp)

pur_inv table has 10 column "invtypid" one of them, here entry only "invtypid" from inv_type table.

Now i want to that read the "invtypid" from listview column "Inv. Type" and convert to "invtyp" in the same place

Edited by Jayanta_1

Attachments 38cb9b592c1852beee39dd83f806d698.PNG 62.37 KB 919faa6249b3636673d7bd6e48948e39.PNG 10.7 KB
1

Well, both tables must be read. You may code something like:

    Public Sub Displayitem()

        Dim cmd As New OleDb.OleDbCommand("SELECT * FROM pur_inv,inv_type WHERE pur_inv.invtypid=inv_type.invtypid ORDER BY purinvdt", cn)
        Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()

        ListView1.Items.Clear()
        Do While dr.Read()
            Dim new_item As New  _
                     ListViewItem(dr.Item("purinvdt").ToString)
            new_item.SubItems.Add(dr.Item("purinvid").ToString)
            new_item.SubItems.Add(dr.Item("prtid").ToString)

            new_item.SubItems.Add(dr.Item("pur_inv.invtypid").ToString)
            new_item.SubItems.Add(dr.Item("taxamt").ToString)
            new_item.SubItems.Add(dr.Item("tottaxblamt").ToString)
            new_item.SubItems.Add(dr.Item("invamt").ToString)
            ListView1.Items.Add(new_item)
        Loop
    End Sub
0

Hay! Done it
I change and replace this line it is done! just I want

 new_item.SubItems.Add(dr.Item("pur_inv.invtypid").ToString)

to

new_item.SubItems.Add(dr.Item("invtyp").ToString)

thanks many many thinks.
God helpe you.

How Many table read at a time.... because want to same work index number column 2 mens (column name Party Name) can I Used for this "and" or ";" or ","

0

hello I do it
DONE!
Intelligence a God gifted quality
You are intelligence.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.