Solved

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

Posted on 2014-03-19
2
278 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Groupbox Control ? 2 30
Securing WEBAPI on Azure 2 28
ASP.NET data base connection 35 46
Stop Git from being my repository 1 27
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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