Results 1 to 3 of 3

Thread: [RESOLVED] Importing Listview data to excel file

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [RESOLVED] Importing Listview data to excel file

    Hello Everyone,

    I have a data in my listview and I just want to save it on excel. Could anybody help me ho to make it. My code goes like this loading to listview.

    Code:
     Dim ConnectionString, CommandText As String
            Dim conn As OleDb.OleDbConnection
            Dim Command As OleDbCommand
    
            ListView1.Items.Clear()
            Try
    
                ' DataGridView1.Refresh()
                ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;"
    
               
                    CommandText = "select * from ClientDetails WHERE F3 NOT LIKE 'Sent%'"
                        
    
                conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
                Command = New System.Data.OleDb.OleDbCommand(CommandText, conn)
    
                conn.Open()
    
                Dim t As New DataTable
                ' initializing its column to complement on how many fields I want to return in my query command 
                t.Columns.Add("v7#3")
                t.Columns.Add("F2")
                t.Columns.Add("F3")
    
    
                ' a method to access read-only the result set. 
                Dim reader As OleDbDataReader = Command.ExecuteReader()
                While reader.Read()
                    ' create new row 
                    Dim r As DataRow = t.NewRow()
                    r(0) = reader("v7#3")
                    r(1) = reader("F2")
                    r(2) = reader("F3")
    
                    ' add a row to a datatable 
                    t.Rows.Add(r)
                End While
    
                ' close reader 
                reader.Close()
                ' close the connection 
    
                conn.Close()
    
                For i As Integer = 0 To t.Rows.Count - 1
                    Dim li As ListViewItem = ListView1.Items.Add(t.Rows(i)("v7#3").ToString())
                    li.SubItems.Add(t.Rows(i)("F2").ToString())
                    li.SubItems.Add(t.Rows(i)("F3").ToString())
    
                Next
    Could anyone help me to save this data to excel? I am really familiar with the excel command. Please help me.

    Regards,

    shyguyjeff
    Last edited by shyguyjeff; Apr 12th, 2009 at 03:37 AM.

  2. #2
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Importing Listview data to excel file


  3. #3

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Listview data to excel file

    I got it toecutter...Have a nice day...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width