• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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

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
VBBRett
Asked:
VBBRett
  • 7
  • 5
  • 2
1 Solution
 
VBBRettAuthor Commented:
is my question clear?
0
 
MacNuttinCommented:
What I would do is write a Data transformation Package in SQL2000 and and execute it from your VB.NET application
0
 
VBBRettAuthor Commented:
That's what I wanted to do but the boss wants it written programmatically.

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
MacNuttinCommented:
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
 
VBBRettAuthor Commented:
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
 
MacNuttinCommented:
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
 
VBBRettAuthor Commented:
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
 
MacNuttinCommented:
Too bad good luck
0
 
VBBRettAuthor Commented:
Thanks!
0
 
VBBRettAuthor Commented:
can you at least tell me how to join an excel spreadsheet and an a sql server table to join fields together?
0
 
mazkotCommented:
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
 
MacNuttinCommented:
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
 
VBBRettAuthor Commented:
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
 
mazkotCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now