Exporting data from sql server to excel from sql server using asp.net

I am new to ASP.net. I have worked on a VB.net code to export data from sql server to excel. The code is simple and works well. Now I am placing this code in a button click event in a asp.net web project. The code has bugs now and I am not sure how to solve those. Any help is appreciated. Thanks.

Protected Sub btnDumpMaterial_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'ErrorMsg.Show("Not Implemented Yet1")
'lblName.Text = txtLast.Text & ", " & txtFirst.Text
Dim DBConnection As String = "Provider=SQLOLEDB.1;uid=sa;password=test ;database=Northwind;DataSource={localhost}"

Dim sql As String = "SELECT CustomerId, CompanyName, ContactName From Customers"
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet

oExcel = CreateObject("Excel.Application")
oExcel.Visible = True

oBook = oExcel.Workbooks.Add
oSheet = oBook.ActiveSheet

Conn.Open(DBConnection, "sa", "test", -1)
rs.Open(sql, DBConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 1)

End Sub

Type 'ADODB.Connection' is not defined
Type 'ADODB.Recordset' is not defined
Type 'Excel.Application' is not defined
Type 'Excel.Worksheet' is not defined
Name 'ADODB' not declared
5/20/2008 6:09:42 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 20

Whats the error ?

Also using office Excel component to generate Excel have lots of issue [some requirement on the server e.t.c] 

Look at following post for easy way of exporting data to excel http://forums.asp.net/t/1038105.aspx 

Kamran Shahid
Sr. Software Engineer
Netprosys Inc.

Remember to click "Mark as Answer" on the post that helps U
5/20/2008 6:57:35 PM

Similar Artilces:

Using VB.NET to export data from SQL Server 2005 to Excel
Hi There, I just want to know how to export data from SQL Server 2005 to an excel spread sheet, using VB.NET?ThanksSJB  Everytime I should export data from SQL to Excel with code, I simply create a ; seperated file (*.csv). So if you want to do the same you can simply use ADO.Net to query your database and get a result set from your tables. Walk trough the rows and get its value and create a textfile with the System.IO namespace. The file can look like: column1;column2;column3 value1;value2;value3 value1;value2;value3 The first row can if you want have the name of the column tha...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers
When I connect SQL Server 2005 to a remote database i get the error: "This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers". Can I confirm it is because: the remote db is of SQL Server 2008? There is a soln mentioned in http://forums.asp.net/t/1324047.aspx Did anybody try this (installing 2008 express: http://www.microsoft.com/express/sql/download/)? I am just checking again, whether it will disturb my existing SQL Server installation, in any means...? Though it is mentioned that it will g...

how do i insert data into sql server using data from textboxes and sql connection and sql command
anyone can give me a simple explaination and code.. Thanx in advance Take a look @ Sample Code: How to add...Sushila Bowalekar PatelVisual ASP/ASP.NET MVPhttp://weblogs.asp.net/sushilasb There are a lot of tutorials out there, but I know they can be a bit confusing as they all approach things slightly differently. Basically a nice simple version would go like this:' *** First set up your connectionDim conConnection As New SqlConnection("server=servername;database=yourdatabase;uid=yourname;pwd=yourpassword;")' *** This line takes care of your sommand text and command connection in one ...

How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net.
Hai All, How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net. I have one Excel Sheet in that sheet 15 Fields (attributes) and 3000 records are there. In this 3000 records i want to store this (Excel) data into  5 related tables on Sql Server Database Using .Net.   How to store Excel Sheet data into Sql Server database. Please help me as soon as possible. Thank You Very Much...Have a Good Day... With RegardsSridhar...

Attach SQL DB to SQL Server 2005 using VB.Net
Is there any way to attach a SQL DB to SQL Server 2005 using VB.Net?  If so can you also set security? Can you rephrase your question? Attach SQL DB from which version of SQL server ? Look up books online for sp_attachdb and sp_detachdb.***********************Dinakar NethiLife is short. Enjoy it.*********************** I have a DB that was created in SQL Server 2005.  I have a website that displays data from systems all over the world.  Each system sends it's data to it's own DB.  The customer can then go to a website and see the data at real time.  What ...

SQL Server 2005 Installation problems with SQL Server Express & SQL Server 2000
Hi Guys, I have had SQL Server Express and Sql Server Management Studio Express installed on my machine for some time and recently tried to install a trial of SQL Server 2005 as well.  (Yes, I'm migrating from Visual Studio Express to Visual Studio Professional, just as in tended!) Everything went fine except that nothing seemed to be installed.  I searched in all the obvious places - both on the Start/Programs menu and on the hard-drive: nothing. A check under Add/Remove Programs showed that Sql Server 2005 Express was installed, but called SQL Server 2005. So after a number o...

creating ssis packagte for sql server to sql serer using C#.net
Hi friendsdoes any one has code or urls which can help me to create the ssis pacakage which will transfer data from sql server to sql server databaseswith some manipulationsthanks so much Lad LaxmikantPune You are probably in the wrong forum.  This forum is for questions relating to ASP.NET Dynamic Data. thanks,David...

Creating a SQL Server linked server to Interbase using 64 bit SQL Server
Hi, I am trying to use the data direct odbc driver for interbase to create a linked server in SQL Server 2008 R2 64bit however, SQL Server reports an "Arcitechure Mismatch" between the System DSN and SQL Server. This did work under 32 bit SQL Server. Is there a 64bit specific odbc driver for interbase? I have tried using the IBProvider trial as well but this fails to work in SQL Server as well. Our Interbase client(s) and server are all 64 bit installations. Thank you Julian Dawson wrote: > Is there a 64bit specific odbc driver for interbase? I think Easy...

Update sql server with data from a different sql server
I have two different sql server databases on different server. I need to do a select from one database and based on the results, update a record on the sql server. thanks, Add the second server as a linked server, then: UPDATE Table1 SET field1=(SELECT field1 FROM Server2.database.dbo.Table1 WHERE ...) WHERE .......   How do I setup the linked server I've looked in the books online and cannot seem to do it. I get to the properites page to add a New Linked server, but what information do I put where. For linked server do I list the server name I am trying to connect to or is...

SQL Server 2000 and SQL Server 2005 in the same server
Can enyone please send me a link to a white paper explaining how to run both SQL Server 2000 and 2005 in the same machine?Thanks. I don't know about the white paper but I had both running on my machine for a while by making the SQL 2000 a named instance. So for SQL 2005 connection strings my server name was (local) while for SQL 200 using the named instance it was (local)\joesql where joesql was the instance nameHope it helps,Joe http://www.joeaudette.comhttp://www.mojoportal.com...

Managing Data between SQL Server 2000 and SQL Server 2005
Hello, I have SQL Server 2000 and 2005 running on the same server. My current system is in SQL Server 2000 and the new system is in SQL Server 2005. My users will be using SQL Server 2000 for the most part,  But for the part the processes that have been migrated to 2005, they will be using SQL Server 2005 as well. The database schema is different on both servers eventhough the data will be similar in most respects. Is there is a way through which any data that is inserted/updated in SQL Server 2000 via content Management System/ manually/ via a batch job, the data is automatical...

using sql server session, does it ALWAYS go to sql server?
Testing a simple web app that's configured to save session in SQL SERVER. I have an array of 250000 ints. Session gets saved in 1 page, and retrieved correctly in another, but I only see 1 transaction in profiler. Also have a large complex object size 250KB, and it get's restored instantly, implying it's not coming from the database. From SQL Profiler, I see one transaction to aspstate db when I leave a page that saves session. Shouldn't I see a gaggle of msgs spew by when I save a large object to session??? All comments appreciated! The short answer is yes. The sessi...

Replicating from SQL Server to Sybase using SQL Server replication
Hi all, I have setup a replication from SQL Server to Sybase ASE using SQL Server transactional replication. This work via the Sybase OLEDB driver and linked server. Connection is working, prublication is defined on SQL Server side, the subscription against the Sybase server and database is working. But I got one huge problem: All character datatypes end up as NULL in Sybase. When I enter a row in the SQL Server table which is publicated all data that is not character (float, numeric, datetime etc.) is replicated and the row is available on Sybase side, but all character columns are...

sql server and sql server express
ok i am puzzled right now....i have a web application connecting to a sql server database....i uninstalled sql server express and installed sql server 2005 full version...i changed the connection string in my application to be Data Source=SKYBANDR62;Initial Catalog=aspnetdb;Integrated Security=True and through the explorer bar i can access my database freely but when i run my application i get this error Server Error in '/' Application. -------------------------------------------------------------------------------- An error has occurred while establishing a...

Web resources about - Exporting data from sql server to excel from sql server using asp.net - asp.net.sql-datasource

Gas Exporting Countries Forum - Wikipedia, the free encyclopedia
The Gas Exporting Countries Forum ( GECF ) is an intergovernmental organization of 11 of the world's leading natural gas producers made up of ...

Facebook policy now clearly bans exporting user data to competing social networks
... of account settings, so it’s unlikely that many users have done this. Google and Facebook blocked or put up roadblocks on importing and exporting ...

Lower dollar a boon for Canberra's wine exporting king
It may mean more expensive holidays for some, but one ACT registered company has enjoyed a profitable time thanks to the sharp fall in the Australian ...

Irish plant shut for exporting horsemeat
Sky News is Australia's leader in 24-hour news.

New online freight marketplace Cargohound aims to be the Uber of exporting
Cargo Hound wants to revolutionise the way goods are shipped from Australia.

Exporting the desperate; out of sight ... and mind
The boats have stopped, the point's been made, so why continue to treat those already ''here'' with such unconscionable cruelty?

Meat market: Andrew Forrest sees fortune in exporting beef to China
China is so desperate for good beef that Australian billionaire Andrew Forrest will be taking sample parcels of steak in his luggage on his next ...

Exporting carbon and hypocrisy: our big growth industry
Never mind our modest cuts to local emissions, new research shows Australia is heading into a carbon export boom.

Spin Cycle: Is Tom Mulcair in favour of exporting bulk water?
The Liberals say Tom Mulcair spoke favourably about the idea of water exports when he was Quebec's environment minister back in 2004. They even ...

Lee Specialties Ltd. Charged With Exporting Prohibited Commodity To Iran
CALGARY - Putting the wrong address on a $15 shipment of synthetic rubber rings has cost an Alberta company $90,000 for violating legislation ...

Resources last updated: 1/23/2016 10:07:16 AM