0

i have codes for adding data to listview from database but there's a problem ..

     Public Sub showmyrecords()
    Dim lvi As ListViewItem
    Dim dt As New DataTable
    Dim ds As New DataSet
    ' Dim intCount As Integer

    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter("Select * from Schedulings where YearLevels = '" & ComboBox3.Text & "' And Sections = '" & ComboBox1.Text & "' ", asconn)
    da.Fill(dt)
    Dim acscmd As New OleDb.OleDbCommand

    acscmd.CommandText = strsql
    acscmd.Connection = asconn
    dr = acscmd.ExecuteReader()

    For Each myrow__1 As DataRow In dt.Rows
        lvi = New ListViewItem()
        lvi.Text = myrow__1(5)
        lvi.SubItems.Add(myrow__1(6))
        lvi.SubItems.Add(myrow__1(7))
        lvi.SubItems.Add(myrow__1(8))
        lvi.SubItems.Add(myrow__1(9))
        lvi.SubItems.Add(myrow__1(10))
        ListView1.Items.Add(lvi)
    Next
End Sub

it produces the rigth data but it produces the same data as many as records that satisfies my query...
please.. help me . . i've been searching it in hours but there's no correct output. thank youuuuu in advance. :)

Edited by kampao00: INADEQUATE INFO

4
Contributors
7
Replies
11
Views
4 Years
Discussion Span
Last Post by kampao00
0

Use a list box instead of list view

before the code clear the list box every time else the value will be repeated...

use a distinct function in ur select query if the query is returning duplicate values

after the executer use a debug.Print("Query: "+ acscmd.CommandText) it will help u to understand the query

With ListBox1
            .DataSource = ds.Tables("TableName")
            .DisplayMember = "ColumnName"


        End With
0

poojav.. how could i make listbox with columns? i'm a newbie. kindly teach me how tosolve my problem?

0

listbox1.Items.Add("Item you want to add 1" & vbtab & "Item you want to add 2")

Edited by Pgmer: spelling mistakes

0

pgmer > i want the item from my database.. and why is it it produce two rows?

0

DbCon = New SqlConnection("data source=.; integrated security=true; database=kehkashan;")
DbCon.Open()

    Da = New SqlDataAdapter()
    Ds = New DataSet
    iRow = 0
    Da = New SqlDataAdapter("select * from tblSupplier order by ID", DbCon)
    Da.Fill(Ds)
    While iRow <> Ds.Tables(0).Rows.Count
        cboSupplier.Items.Add(Ds.Tables(0).Rows(iRow).Item(2))
        iRow = iRow + 1
    End While


    it is a combo box filling method .. try it in Listview box ... 
    ..




    .
    Me.ListView1.Clear()
    Me.ListView1.LargeImageList = Me.ImageList1
    Me.ListView1.View = View.LargeIcon
    Me.ListView1.Items.Add("Sale", "Sales", 0)
    Me.ListView1.Items.Add("Pur", "Purchases", 1)
    Me.ListView1.Items.Add("Exp", "Expences", 2)
    Me.ListView1.Items.Add("SR", "Sale Return", 3)
    Me.ListView1.Items.Add("Cat", "Catogory", 4)
    Me.ListView1.Items.Add("Cust", "Customer Managment", 5)
    Me.ListView1.Items.Add("Sup", "Supplier Managment", 6)
    Me.ListView1.Items.Add("Emp", "Staff Managment", 7)

Edited by saleem.mukhtiar: add more code

0

@saleem items produce in one column only.. and repeated 8 times.

0

i figure out already it alreadyyyyy with the help of my friend . :D

here's the final code.
just want to share.

Public Sub showmyrecords()
    Dim lvi As ListViewItem
    Dim dt As New DataTable
    Dim ds As New DataSet
    ' Dim intCount As Integer

    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter("Select * from Schedulings where YearLevels = '" & ComboBox3.Text & "' And Sections = '" & ComboBox1.Text & "' ", asconn)
    da.Fill(dt)
    Dim acscmd As New OleDb.OleDbCommand

    acscmd.CommandText = strsql
    acscmd.Connection = asconn
    ListView1.Items.Clear()
    For Each myrow__1 As DataRow In dt.Rows
        lvi = New ListViewItem()
        lvi.Text = myrow__1(5)
        lvi.SubItems.Add(myrow__1(6))
        '6 is 7th column in datatable!!!
        lvi.SubItems.Add(myrow__1(7))
        'and so on...
        lvi.SubItems.Add(myrow__1(8))
        lvi.SubItems.Add(myrow__1(9))
        lvi.SubItems.Add(myrow__1(10))
        ListView1.Items.Add(lvi)

    Next


End Sub

thank youuuuuuu to those who replied. :) it helps me. :) godbless. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.