Solved

How would I connect this Excel Spreadsheet with the SQL Server table and update or insert the records into the table?

Posted on 2006-06-28
14
178 Views
Last Modified: 2010-04-23
I am writing a VB.NET program and I understand I would need an ole db connection string for the Excel spreadsheet and a sqlconnection string for the SQL Server database and table.  My question for you is how would I get them to work together?  Here is the problem.  Let's say the fields are identical, meaning each column has the same name..how would I use the excel spreadsheet to upload into the SQL Server Database.  I'm going to write a query, now assume the Excel spreadsheet is a table, and the SQL Server table is in the SqL Server database.  How do I get them to work together?  Below is an update query, but if there are new records, I want them inserted from the Excel spreadsheet.  All this has to be done programmatically from a vb.net application.  But here goes.

Assume the excel spreadsheet is named MARCHDETAILS, the SQL Server database name is Work and the table in the SQL Server database is named Valuation.

Now I haven't put the Insert query in because I am not sure how to go about it.  Please help!

UPDATE
Work.Valuation
SET
 Work.Valuation.Insured = MARCHDETAILS.Insured,
Work.Valuation.LossDescription = MARCHDETAILS.LossDescription
FROM
MARCHDETAILS
INNER JOIN Work.Valuation ON MARCHDETAILS.LOB = Work.Valuation.LOB
and MARCHDETAILS.PolicyNO = Work.Valuation.PolicyNO
and MARCHDETAILS.OccuranceNO = Work.Valuation.OccuranceNO
and MARCHDETAILS.PolOccNO = Work.Valuation.PolOccNO
and MARCHDETAILS.PolComm = Work.Valuation.PolComm
and MARCHDETAILS.LossDay = Work.Valuation.LossDay
and MARCHDETAILS.RiskState = Work.Valuation.RiskState
and MARCHDETAILS.FirstNotice = Work.Valuation.FirstNotice
and MARCHDETAILS.ValnMo = Work.Valuation.ValnMo
and MARCHDETAILS.AccYr = Work.Valuation.AccYr
0
Comment
Question by:VBBRett
  • 7
  • 5
  • 2
14 Comments
 

Author Comment

by:VBBRett
ID: 17002806
is my question clear?
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 17002962
What I would do is write a Data transformation Package in SQL2000 and and execute it from your VB.NET application
0
 

Author Comment

by:VBBRett
ID: 17002997
That's what I wanted to do but the boss wants it written programmatically.

0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 17003016
Ask your Boss for clarification he may just want a VB.NET app that does the task. That the VB app executes a DTS as part of the solution may not matter to him. It is the standard way where the SQL server is 2000

Look here:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21174856.html
0
 

Author Comment

by:VBBRett
ID: 17003040
Would a DTS decifer between whether it would update or insert a new record?  Does it know if there is something brand new or if something is being updated?
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 17003233
I don't know so what I would do is use DTS to import MARCHDETAILS  into Work as a temp table then execute a stored proc from the DTS to handle the insert or updating of the records and finally drop the temp table
0
 

Author Comment

by:VBBRett
ID: 17003583
My manager wants nothing to do with DTS, so I am back to the drawing board on how I'm doing it programmatically with SQL Server and VB.NET on it's own.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:MacNuttin
ID: 17003719
Too bad good luck
0
 

Author Comment

by:VBBRett
ID: 17003733
Thanks!
0
 

Author Comment

by:VBBRett
ID: 17003739
can you at least tell me how to join an excel spreadsheet and an a sql server table to join fields together?
0
 
LVL 3

Expert Comment

by:mazkot
ID: 17007093
You can place  your excel data in a dataset and work from there for the conditions to update or insert to the sql server.

0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 17009921
That's right you can pull in the SQL data table 'work' as well into a dataset in VB and join it to dataset for 'MarchDetails' using the designer in Visual Sudio
0
 

Author Comment

by:VBBRett
ID: 17010442
Well, I programmed the dataset in for both the Excel spreadsheet and the SQL Server table connection.  How do I pull that into the the designer after you code it in?
0
 
LVL 3

Accepted Solution

by:
mazkot earned 500 total points
ID: 17015039
just used the unique key as a condition to check if it exist in the sql server.. if it exist use the same key to update.. else insert.. you don't need to set data in the sql server in a dataset..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Round a string to two digits 12 30
Copy/Clone an object. 9 29
Vb.Net Date Formatting Assistance 4 35
Run a batch file when a Crystal Report is opened 5 11
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now