There are many ways to export data from SQL Server to Excel but I think the one way to do it by real simple coding is to export the data as an XML file and then opening it in Excel.
First we fill the data in a DataSet and then export that data to an XML file. Although the file is an XML one, I give it an extension of ‘.xls’ so that Excel opens it by default and then it can be saved it as the Excel format in some other sheet.
Dim con as SqlConnection
con = New SqlConnection(“Data Source=SERVER; Initial Catalog=dbTest;uid=sa;pwd=123″)
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = “spExportData”
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
Dim ds As New DataSet
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
Dim savefileName As String = Application.StartupPath & “\ExportedFile.xls”
If in a table, some columns occasionally contain null values, then while trying to retrieve the values, the following error is shown:
Conversion from type ‘DBNull’ to type ‘String’ is not valid.
To solve this problem, we can check if the Datareader has a null value for the column, and if yes, then just getting the TextBox to show an empty string.
If DBNull.Value.Equals(dataReader1(“Column_Name”)) Then
TextBox.Text = “”
TextBox.Text = dataReader1(“Column_Name”)
Jack D. Herrington (a senior software engineer with more than 20 years of experience) writes in detail on how to build a chat system on a web application using Ajax, XML and PHP.
Stanford University has made available its iPhone Application Programming course for this year on iTunes U as biweekly video podcasts and slides in pdf format.
It’s not everyday that you get a chance to be taught by two Apple engineers from Stanford University.
Here is another excellent course from iTunes U video podcasts, for students wishing to learn Object Oriented Programming. Provided by Andrew Cain of Swinburne University of Technology.
Sans.org has published a list of top 25 most dangerous programming errors. These errors have been compiled by a team of US and other international anti-cybercrime organizations. Two of these erors lead to more than 1.5 million security breaches during 2008.
Introduction to Ruby for Mac OS X : The Principle of Least Surprise by Jim Menard
This course is from The University of New South Wales, Sydney Australia, and is the complete video recording of lectures in progress. It is free to download to everyone everywhere regardless of whether you have an iTunes store account or not. I have gone through 25 out of 46 available lectures till now and I find it really excellent with the tutor keeping the students very interested in the stuff being taught while maintaining a real interactive note throughout. The image below describes the course in full.
Click on the image to view it in full size.
An article from InfoWorld, not just blatant fanboyism but an analysis supported by solid ground. Read “Why developers prefer Macs“.