?
Solved

Connection strings for two different sources (Excel & MS SQL)

Posted on 2014-03-19
2
Medium Priority
?
298 Views
Last Modified: 2014-04-13
I have a connection string to read from a SQL data base and another to read from an Excel spreadsheet. However how do I handle a situation where I want to read records from an excel spreadsheet and insert them into my SQL database

example
Insert into DCR_transaction_master  SELECT * from [DCR_transaction_master$] where T2_transactionId='&TransactionId'

What connection string do I provide with this type of statement which is reading from Excel and writing to SQL DB?

regards
Pat
0
Comment
Question by:pclarke7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 1500 total points
ID: 39939548
Pat:

This article seems to provide a really good way to do what you want, and it also shows the use of multiple connection strings, as you are asking about that:
http://code.msdn.microsoft.com/office/Imoprt-Data-from-Excel-to-705ecfcd

However, if that's not enough, I would do it this way. It might not be the fastest or most efficient, but it would work:

1. Write a method to insert the data into the SQL database using the connection string using SQLConnection and SQLCommand. Use the "using" statement:

Using (SqlConnection conn = new SqlConnection("SQL DB Connection String))
{
   // do the insert using a SqlCommand
}

Have this method take in the appropriate data structure (a Class or Struct as you would define it).

Then, in a separate method, read each row from the Excel sheet and populate the structure or class. Pass in that populated structure/class to the method that inserts it into SQL.
0
 

Author Closing Comment

by:pclarke7
ID: 39997785
Thanks Dan7el,
apologies for delay in replying

regards
Pat
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question