2 Replies - 4915 Views - Last Post: 22 February 2011 - 03:06 AM Rate Topic: -----

#1 Qnatz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 11

Display database on Listview

Posted 21 February 2011 - 05:32 AM

Hey guys
can some one help
i've this code with just the display code missing.
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim con As SqlServerCe.SqlCeConnection = New SqlServerCe.SqlCeConnection("Data Source=" & Application.StartupPath & "\StocksDB.sdf")
        con.Open()
        Dim cmd As SqlServerCe.SqlCeCommand
        cmd = New SqlServerCe.SqlCeCommand("Select* from Stocks", con)
        Dim rdr As SqlServerCe.SqlCeDataReader
        rdr = cmd.ExecuteReader()

       'code to display on listview

        rdr.Close()
        con.Close()
    End Sub


Qnatz

Is This A Good Question/Topic? 0
  • +

Replies To: Display database on Listview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Display database on Listview

Posted 21 February 2011 - 06:24 AM

Assuming a listview called ListView1

While rdr.Read()

  dim LV as new ListViewItem
  LV.Text = rdr("SomeFieldNameInYourDatabase").ToString 'Fills the first column of the row
  LV.SubItems.Add(rdr("SomeFieldNameInYourDatabase").ToString 'Fills the 1st subitem (2nd column)
  LV.SubItems.Add(rdr("SomeFieldNameInYourDatabase").ToString 'Fills the 2nd subitem (3rd column)
  'You can repeat subitems for each column you have in your listview.
  'Then I always store the primary key in the .Tag
  LV.Tag = rdr("PrimaryKeyColumnName").ToString
  'At this point you have created a listview item (a row containing multiple columns)
  'Once you have everything you need, just add the listviewitem (LV) to the listview
  ListView1.Items.Add(LV)

End While

This post has been edited by CharlieMay: 21 February 2011 - 06:24 AM

Was This Post Helpful? 1
  • +
  • -

#3 Qnatz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 11

Re: Display database on Listview

Posted 22 February 2011 - 03:06 AM

Hey CharlieMay Thanks for you quick reply.
First i would apologize for not reporting
my advance. It was last night when i got a clue
n this is my code
While rdr.Read
            ListView2.Items.Add(Trim(rdr("SysDate"))) 'col no. 1
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("SysDate"))) 'col no. 1
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("WNDate"))) 'col no. 2
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("DocNo"))) 'col no. 3
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("StockIn"))) 'col no. 4
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("StockOut"))) 'col no. 5
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("FromTo"))) 'col no. 6
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("Crop"))) 'col no. 7
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("Variety"))) 'col no. 8
            ListView2.Items(CInt(intCount)).SubItems.Add(Trim(rdr("Note"))) 'col no. 9
            intCount = intCount + 1
        End While


Actually when i got this i just slipped btn my sheets.
The only problem The SysDate Column is filled starting 5 rows
down leaving a blank range. ie Column1 starts at row5, Column2...9
fill correctly from row 0.

My other problem permanently saving to the database which
am posting in another post.
Regards
Qnatz
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1