Comment on Tutorial - How to export from database to excel using VB.net By Issac
Comment Added by : John McCode
Comment Added at : 2013-05-24 07:57:31
Comment on Tutorial : How to export from database to excel using VB.net By Issac
you do the same as after
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnn As SqlConnection
Dim sql As String
Dim i, j As Integer
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
cnn = Connection.getConnection()
cnn.Open()
sql = "SELECT * FROM tblNVcanhan"
Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet
dscmd.Fill(ds)
For i = 0 To ds.Tables(0).Columns.Count - 1
xlWorkSheet.Cells(1, i + 1) = ds.Tables(0).Columns(i).ToString()
Next
For j = 0 To ds.Tables(0).Rows.Count - 1
xlWorkSheet.Cells(j + 2, 1) = ds.Tables(0).Columns(j).ToString()
For i = 0 To ds.Tables(0).Columns.Count - 1
xlWorkSheet.Cells(j + 2, i + 1) = ds.Tables(0).Rows(j).Item(i).ToString()
Next
Next
xlApp.Columns.AutoFit()
'xlWorkSheet.SaveAs("D:\vbexcel.xlsx")
'xlWorkBook.Close()
MsgBox("You can find the file D:\vbexcel.xlsx")
xlApp.Visible = True
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
cnn.Close()
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
View Tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Archived Comments
1. i don't use mysql,but oracle.
how to resolv
View Tutorial By: Mike Zhu at 2009-06-23 19:20:06
2. not working on mozila firefox 3.1. I tested it.
View Tutorial By: sushma at 2009-10-08 00:07:47
3. Better theory for those who have just started.
View Tutorial By: kunal at 2010-05-13 05:55:05
4. Very Nice Example...!!thanks
View Tutorial By: Shafique khan at 2013-01-22 18:58:22
5. any help please I'm getting this exception
View Tutorial By: Bull at 2012-01-02 17:22:18
6. Awesome, now I can say I've fully understood volat
View Tutorial By: Andrew at 2012-01-13 18:19:15
7. You should give more specification on exactly whe
View Tutorial By: Abhijit at 2013-03-09 20:14:21
8. hi..i can send 4 or 5 sms per mnt..is there any wa
View Tutorial By: rahul at 2011-02-11 00:17:51
9. Dear All...................,
I have run the
View Tutorial By: Ashraf Abu Aisheh at 2008-12-01 13:52:42
10. How can i read PDF files from external memory(SD c
View Tutorial By: Aswanth at 2014-03-31 09:46:26