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
177 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now