We help IT Professionals succeed at work.

SQL query to Office applications

strictly_mk
strictly_mk asked
on
235 Views
Last Modified: 2013-11-05
Hi,

I'm using MS Visual Web Developer Express 2005 and SQL Server 2005 Express. I have a database backend and a few web pages for the front.

I am building a contacts database which is supposed to be able to create excel spreadsheets for mail merge data sources and also to be able to create Outlook contacts from the data stored in the database.

I have a gridview that shows the results of a database query with code like this...

Public Function generatedata(ByVal conn As String, ByVal query As String) As DataTable
        Dim connection As New SqlConnection(conn)
        Dim command As New SqlCommand
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = query
        Dim adapter As New SqlDataAdapter(command)
        Dim buffer As New DataTable
        adapter.Fill(buffer)
        Return buffer
    End Function

conn_string = "Data Source=.\SQLEXPRESS;AttachDbFilename=" ....
query = "SELECT * FROM Contact WHERE....
results = generatedata(conn_string, query)
GridView1.DataSource = results
GridView1.DataBind()

I have check boxes on each row and I have code that takes the primary key (ContactID) for that table and puts them in an array.

So to cut a long story short I want to click a button, pass those ContactIDs to a sql query (or stored procedure), create a new excel spreadsheet, fill it with the query result and save it to the user's desktop.
Also a button to create an Outlook contact and fill the fields with the relevant data is what I need but I don't know how to write code to interact with the two applications. Any ideas will be greatly appreciated.

strictly_mk
Comment
Watch Question

Christopher KileSenior Software Analyst
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Into Page_Load() of your ASPNET page add
     Response.ContentType = "application/vnd.ms-excel" ;
when you want to output as EXcel document and browser (IE for sure) will take care of it

Author

Commented:
Thank you cpkilekofp and gelbert for your suggestions. I'll test those ideas out asap. Would you by chance know how to access Outlook components directly?

I would prefer not to use csv files to import as contact data. I don't want the user of my page to see the file being created when importing into outlook - I want to give the impression it imports directly.

How can I automate the creation of a csv file/ excel spreadsheet/ outlook contact. Write the data, then save/close?

My appologies for the persistent questions.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.