Data Conversion Errors On Excel Import Into Existing Table

Aug 28, 2006

Recently installed Sql Server 2005 client and am now attempting to import data from a spreadsheet into an existing table. This works fine with Sql Server 2000 but I am getting data conversion truncation errors that stop the process when this runs using import utility in Sql Server 2005.

Any help would be appreciated.

View 1 Replies


ADVERTISEMENT

Import Data From Excel Into Existing Table....

Nov 27, 2007

Hi guys, I need to import all data from Excel spreadsheet to a Sharepoint Content Database (SQL Server).Please suggest the
best way to do this.
For this when i run the Import wizard under Tasks--> Import in Management Studio 2005 ....it asks me to choose the database
name etc....but How to use the Import/Export Wizard to Export Data from a .xls source to an existing table in a database....that is i need to append/insert my excel data into an existing table.

Thanks,
Kon

View 2 Replies View Related

How Do Create Table From Excel (based On Excel Column Name) And Import Data From It?

Jun 14, 2006

l've the following situation,

l've some excel files controlled by Vendor which changing frequently. The only thing does not change is the header name of each column.

So my question is, is there any way to create a new table based on the excel file selected including the column name in SSIS? So that l can use the data reader as source to select those columns l am interested on and start the integration.


Thanks.

Regards,
Yong Boon, Lim


p/s : The excel header is at the row 7.

View 3 Replies View Related

How To Import CSV Data Into Table With Foreign Key Conversion

Nov 17, 2013

Our SQL 2008 R2 relational database has tables with foreign key relationships for part numbers. We receive production data from a separate program and we need to import the CSV data into our database application.

The problem is our separate program creates a CSV file with the actual part number "362S162-33". In our database we have a separate parts table (example: 362S162-33 has identity "15").

We need to import data into a production table that has a "part number" (FK) column.

How can we, when importing, cross-reference the "parts table" to convert the part number to the identity number. We have thousands of parts, so we need this change of part number column to the FK identity automatically on import.

Production Table:
idComponent (PK), [1000]
ComponentName, [Assembly108]
idPartNumber (FK), [15]
ComponentLength, [230.5]
UserMessage, [Assembly is 230.5 inches using 362S162-33]
Qty; [1]

View 4 Replies View Related

Exporting Excel Data To An Existing SQL Table

Nov 21, 2007

Hello,

I would like to create a stored procedure that opens a data connection for an excel file that I have saved. I would then like to export the excel data into an existing SQL table. Can anyone tell me the best way to go about this?

Thanks

View 2 Replies View Related

Export Data From Excel Into An Existing SQL Table

Dec 17, 2007

Hi everyone, I am new with SQL and I tried to use the code below to export data from Excel into an existing SQL table, but I keep on receiving the following message.

Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".


To export data from Excel to existing SQL Server table,

Insert into dbo.Base_Intraday Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:Shortcuts6 - Bolsa de Valores1 - Bolsa de Valores - Bovespa;HDR=YES',
'SELECT * FROM [Link$]')

Can anyone help me on this?

Thanks

View 9 Replies View Related

Character Conversion Errors SQL To Excel

Feb 5, 2008

Hopefully this is an easy one.

But in both the importexport utility and from SSIS. "#" become "." (aka pound to period) in column headers. So for example [# of errors] becomes [. of errors]. Now I truly do not ever remember having this issue before but then again I have don't remember having to construct field names with a various assortment of characters that are randomly strewn about as though someone discovered the symbol picker recently and had decided to employ it to make the a spreadsheet a more interesting place. Hence after a good day of time wasted. (as I considered doing an alter table after the sheets were put out.. and then thought better of it.) I seek guidence here. Thanks in advance.

View 2 Replies View Related

Import Excel Data To --&> SQL Db Table

Oct 8, 2007

Hey folks,
My first post and I hope not my last!!

I am very new to the entire world SQL Server databases. I am starting from scratch.

Currently I have a little Website I am doing for myself that is .asp based and will allow users to query some sports boxscores. I hope to create a user interface that will allow folks to seperate team results based on certain criteria...

It is just a hobby of mine that I have been doing for year with excel and now hope to let others like me do it aswell.

here is what I got.

MSSQL 2005 Server with a database.
Iam using SQL 2005 Server Express Studio. Therefore, do not have access to SSIS or DTS or anything like that.

However, I want to import several hundred records into a db I created (hosted by Crystal tech). Since, I don't have access to the Server root directory, I can't use the BULK INSERT statement.

I am looking for a method to query an excel file (or .csv something..) that is stored on my local drive and upload it to the Server db tables.

I would like to do this either through SQL with a query. Or I would to add this VB code to the current VB that I use in my Excel file.

any ideas..??

Thank you for supporting me in advance.

View 8 Replies View Related

Import Excel Data Into Sql Table

Aug 20, 2007

Hi!
I have to develop an application for transfering data from an excel file into a sql table.The excel file is uploaded to a server.The database(and the table) is on another server.At first,I used openrowset for transferring data to the table.My sql command looked like this(in my asp page):

SQLstr = "SELECT * INTO dbo.shopping_TSR FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database="+Server.MapPath("upload/tmb2.xls")+";hdr=yes', 'SELECT * FROM [Sheet1$]')"

I kept getting this error:
[Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0'IDBInitialize::Initialize returned 0x80004005: The provider did not give any information about the error.]

After reading a few articles,I think the cause of my error is that the excel file is uploaded into the folder where the asp script is located.I have 2 servers : one running the asp scripts and one containing the database.
Is my error generated by the fact that the excel file is on a different server than the sql server?How could I make this work?


View 4 Replies View Related

Data Import From Excel To Sql 2000 Db Table

Feb 26, 2008

i have a table in sql 2000 db and want to import data from excel sheet in to the table.
my table = Table1
excel file = data.xls
is there a simple method where i can import data from the sheet into the existing table?

View 5 Replies View Related

Import Data From Excel Spreadsheet Into A Table

Jul 17, 2013

I am using the import wizard in SQL Server 2008 R to import data from an Excel spreadsheet into a table I have created.

The spreadsheet contains 3 columns that SQL recognises as DOUBLE and they contain a 1 or 0. What data type do the corresponding fields in SQL table need to be? I have tried BIT, INT and FLOAT but keep getting an error (can't view details of the error because I get chucked out every time the error pops up). I know the problem is with the DOUBLE data because when I 'ignore' those columns the import works fine.

View 2 Replies View Related

Import Excel Data Sheet To SQL Table - How To ??

Mar 18, 2006

I need to make a script in SQL 2005 to import data from an Excel sheet into a SQL table.
I am using the wizard to import now.
Import from Excel 2000. First row of the excel sheet has column names.
Excel file name is: EXL.xls, sheet name is: Sheet1
Destination sql database name is: NM, table name is: Sht1
I use SQL Server Authentication to access the database.
User name: ABC and password: DEF
Database name is: DB
I am using the following setting when importing now:
- Delete rows in destination table
- Enable identity insert

View 3 Replies View Related

Import Excel Data To A Sql Server Table

Sep 11, 2007

Hi,

I need to import data from more than 10 excels having the same format in to a single sql server table.

I tried to use

INSERT INTO MyTempTable
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 11.0;Database=C:Book1.xls', [Sheet1$])

but got the below error
Ad hoc access to OLE DB provider 'Microsoft.Jet.OLEDB.4.0' has been denied. You must access this provider through a linked server.

If DTS package is used then I am not sure how I can place 10 excels at a time so that they can be picked one by one and data is imported in to table.

Please help.

Thanks,
Vimalraj

View 1 Replies View Related

Import Excel Spreadsheet Data Into SQL Server Database Table Using SqlBulkCopy

Dec 13, 2007

 
Hi, I'm a Student, and since a few months ago I'm learning JAVA. I'm creating an application to call and compare times. For this I create in Excel a time table which is quite big and it would be a lot of typing work to input one by one the data in each cell in SQL Server, considering that I have to create 8 more tables. I was able to retreive the data from excel usin the JXL API of JAVA but it doesn't give all the funtions to perform math operations as JDBC. That's why I need to move the tables from Excel to SQL.
I found this site http://davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx which gives a code to do so, but I guess that some heathers are missing or maybe I don't know which compiler to use to run that code, I would like you help to identify which compiler use to run that code or if there is some vital piece of code missing.// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft .Jet.OLEDB.4.0;Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand ("Select ID,Data FROM [Data$]", connection);

connection.Open();

// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=.; Initial Catalog=Test;Integrated Security=True";

// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "ExcelData";
bulkCopy.WriteToServer(dr);
}
}
}
On the other hand in this forum I that someelse use that link but implements a totally different code which I'm not able to compile also http://forums.asp.net/p/1110412/2057095.aspx#2057095. It seems this code works as I was able to read, but I do not know which language is used.
Dim excelConnectionString As String = "Provider=Microsoft .Jet.OLEDB.4.0;Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;"""
 
' Using
 
Dim connection As OleDbConnection = New OleDbConnection(excelConnectionString)
 
Try
 
Dim command As OleDbCommand = New OleDbCommand("Select ID,Data FROM [Data$]", connection)
connection.Open()
 
' Using
 
Dim dr As DbDataReader = command.ExecuteReader
 
Try
 
Dim sqlConnectionString As String = WebConfigurationManager.ConnectionStrings("CampaignEnterpriseConnectionString").ConnectionString
 
' Using
 
Dim bulkCopy As SqlBulkCopy = New SqlBulkCopy(sqlConnectionString)
 
Try
bulkCopy.DestinationTableName =
"ExcelData"
bulkCopy.WriteToServer(dr)
 
Finally
 
CType(bulkCopy, IDisposable).Dispose()
 
End Try
 
Finally
 
CType(dr, IDisposable).Dispose()
 
End Try
 
Finally
 
CType(connection, IDisposable).Dispose()
 
End Try
 
Catch ex As Exception
 
End Try
The Compilers I have are: Eclipse, Netbeans, MS Visual C++ Express Edition and MS Visual C# Express Edition. In MS Visual C++
Thanks for your help.
 Regads,
Robert.
 

View 4 Replies View Related

SQL Server 2014 :: Import Data From Excel To Table - Null Instead Of 0 In Columns

Oct 29, 2013

I have a excel sheet with some data and blank columns. I have a ssis package using to import data from excel to sql table. For blank excel columns it is importing as null instead i want to show them as '0'. If data comes in it should update the data.

View 8 Replies View Related

SQL 2012 :: Using Excel In SSIS To Import Data From Spreadsheet To Staging Table?

Feb 5, 2015

I'm trying to use Excel in SSIS to import the data from spreadsheet to a staging table. The package runs well from the web server using SSMS. But when I deploy and try to execute the package, I'm getting the below error. I've a question, whether I've to install the AccessDatabaseEngine driver in SQL database server or the web server where I'm executing the SSIS?

Error: The requested OLE DB provider Microsoft.Jet.OLEDB.4.0 is not registered. If the 64-bit driver is not installed, run the package in 32-bit mode.

View 3 Replies View Related

Mass Import Into Existing Table

Sep 17, 2013

I have an existing SQL table that I want to import 300,000 rows into. I have copied the table headers into Excel and added all the rows but constantly getting multiple errors no matter what way I try to import it.

So far tried Import Method from SQL Management Studio, BULK INSERT and SQL Script. What is the easiest way?

If I try this

select *
into Coupon FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:coupon.xls;HDR=YES',
'SELECT * FROM [coupon$]')

I get

OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.

View 9 Replies View Related

SQL 2012 :: Importing Excel Table Into Existing Table?

Aug 25, 2014

I am using the DTS wizard and having problems importing excel into an existing table.

Problem is that various column in excel are defined as double in the wizard but in my db table it is defined as an integer.

How do I get around this issue so the data types in excel can match up accordingly to my defined data type in my db table?

The wizard does a bad job of guessing the correct data type.

I have heard of using a staging table to import from excel and using that as my source to import into my existing table.

View 8 Replies View Related

Import Data On 2005, Many Errors

Jul 25, 2006

I have a client who we moved to our new web server and sql 2005 server from a sql 2000 server. I detached the database from sql 2000 and attached it to 2005. I also just set the compatibility to 2005 also.

My client used enterprise manager to import data into the tables on the sql 2000 just fine. Now using the SQL Management Studio, importing the same table produces all kinds of error, truncation errors, etc.

I have played with a bunch of the settings, did the "Suggest Types" options, but I still just get a bunch of errors. It seem to get it to work I have to go in on the columns of the flat file i am importing and change EVERY COLUMN field to match the table i'm importing too. That is just too much work.

I basically have a 2 record text file i easily imported to sql 2000. but importing into sql 2005 proves to be a *** load of work! Aren't products supposed to get better with future releases? What am I doing wrong?

I've tried the sql native client and the oledb sqlserver client and get the same results.

Any ideas?

View 1 Replies View Related

Importing An Excel List Into An Existing Table?

Jan 7, 2008

Hi everyone!

I would like to import an excel list into an existing sql server table.

How ist that possible?

Thanks a lot in advance!

Greetings from Austria, landau

View 3 Replies View Related

Excel Destination: Write Over Existing Data

Jan 26, 2007

I have a daily package that extracts some data and writes it into an excel file. I want to write over the existing data, but the excel destination only appends the next free location in the worksheet. I tried using a SQL task to grab the file, set all the cells = NULL and then run the rest of the package, thinking it would see the null cells as empty and write in them, but somehow it knows where the previous data ended and keeps appending further down in the workbook.

Does anyone know of a workaround so I do not have to delete and re-create the file everytime?

TIA,
Sabrina

View 14 Replies View Related

Data Conversion To Excel

Dec 3, 2007

Hi i've 2 questions.

Q1 . I'd like to know if i have a data conversion before i export my data out to excel will it hold the data types in excel.


Q2. If i sort the data before i export my data out to excel will it hold the sort

View 1 Replies View Related

Importing Data From Excel To Update Existing Fields

May 12, 2004

I have an excel file that contains column A with names of components and products followed by column B which has each respective quantity on hand. I want to import that data to our website's SQL database that has a products table with a column, Pf_ID, that has only product names not component names and In_Stock which contains out-dated information that I want updated from column B of the excel file.

I think I've figured out how to use DTS and update the two fields, but I'm afraid that when everything runs new entries will be created with component information. Is it possible to specify that only rows where Pf_ID matches some row in column A that same row's column B will be used to update the data in In_Stock. I may have just made things too confusing than they need to be, but I don't have much experience with EM or Excel.

I'm also considering trying to write a macro that will match Pf_IDs in an exported excel file of the products table and take rows out of the excel file with current quantity information putting them in a new excel file to import into the website's database.

Please help, this is getting really confusing.

View 4 Replies View Related

Inporting Attached Excel File Into Existing Table Adding Info

Jul 25, 2005

Hi all,I have a problem and need some ideas.What I have done: I created a page to upload an excel file into a SQL Server table along with some customer info (from the login, day, etc.). This excel file contains several rows (some of them may be blank) and columns (also some may be blank). The file is stored in an image object.The file will be checked (they want to do it manually, because contents is a problem). If they say it is OK, I want to run a program to add a record into an existing table with the request no. (from the first table, where the object is stored) and all the information available from the filled rows (first row is header). I have a column, which can be checked, if the row contains data or not.Any ideas?I know how to read from and write the contents of the object to a field in the SQL table. Can I use this?Thanks for any idea / code / link.

View 2 Replies View Related

Data Conversion Error On Excel Destination

Jan 9, 2007

I am inserting rows using OLEDBDestination and want to redirect all error rows to EXCEL Destination.

I have used Data Conversion Transformation to Convert all strings to Unicode string fields before sending it to Excel Destination.

But its gives the following error.

[Data Conversion [16]] Error: Data conversion failed while converting column 'A' (53) to column "Copy of A" (95). The conversion returned status value 8 and status text "DBSTATUS_UNAVAILABLE".

[Data Conversion [16]] Error: The "output column "Copy of A" (95)" failed because error code 0xC020908E occurred, and the error row disposition on "output column "Copy of A" (95)" specifies failure on error. An error occurred on the specified object of the specified component.



Can someone please tell me what should I do to make it work?

Thanks,

View 22 Replies View Related

Exporting SQL Server Data To Excel Errors

Nov 8, 2007

I thought this should be easy... but, so far it has not been. I want to export data from SQL Server using a query to an Excel spreadsheet. I'm using SQL Server ODBC for the source connection and a Connection To Excel as my destination source. The spreadsheet exists and has the first row with column names. My mappings and query work fine. I don't have any warnings before trying to execute. BUT it will not insert the data into the spreadsheet. Here are the errors I'm getting:
[Destination - TEST$ [28]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21.
[Destination - TEST$ [28]] Error: Cannot create an OLE DB accessor. Verify that the column metadata is valid.
[DTS.Pipeline] Error: component "Destination - TEST$" (28) failed the pre-execute phase and returned error code 0xC0202025.

TEST$ is the sheet that I am trying to add the data to and I'm using Excel 2003.


My query is simple:
SELECT OrderDate AS Date, VendorName AS Vendor, Item AS Product, TotalCost AS Amount
FROM osv_Ordercaldwecs319
All fields have been converted to varchar although I started with not trying to convert them so I have tried both ways.

What is causing the errors? Where can I look to find the problem? I'm guessing it's a data conversion problem but I made everything varchar and no formating on the spreadsheet (although I've tried that as well)

HELP please!!!
Thanks,
Linda

View 11 Replies View Related

Csv File Import: Bulk Insert Data Conversion Error (type Mismatch)

Sep 27, 2004

Hi,

Iam trying to import data from a csv file into my table in SQL Server 2000. My table is called as temp_table and consists of 3 fields.

column datatype
-------- -----------
program nvarchar(20)
description nvarchar(50)
pId int

pId has been set to primary key with auto_increment.

My csv file has 2 columns of data and it looks like follows:

program, description
"prog1", "this is program1"
"prog2", "this is program2"
"prog3", "this is program3"


Now i use BULK INSERT like this

"BULK INSERT ord_programs FROM 'C:datafile.csv' WITH (FIELDTERMINATOR=',', ROWTERMINATOR='', FIRSTROW=2)"

to import data into my table in SQL server and it gives me this error

"Bulk insert data conversion error (type mismatch) for row 2, column 3 (pId)"

I guess i have to use fileformat or something since i dont have anything for pId field in the csv file to make it work...

Please help me out guys and please post a snippet of code if you have.

Thank You.

View 2 Replies View Related

Errors In Table Analysis Tools For Excel DataMining AddIn

Mar 2, 2007

It's an error "The 'MINIMUM_DEPENDENCY_PROBABILITY' data mining parameter is not valid..." always I try to run Analyze Key Influencers Tool. How it's possible to fix it?

View 5 Replies View Related

Import From Excel To More Than One Db Table

Feb 7, 2008

Hi,

I have a large excel file that contains some contact information and includes the following columns:
Company Name, Company Fax, Company Address, Contact Person

In the db I have 3 tables that I need to insert into:
Company table
id ([uniqueidentifier] NOT NULL DEFAULT (newid())
Company Name nvarchar (200)
Company Fax nvarchar (200)
Company Address nvarchar (200)

Contact table
id ([uniqueidentifier] NOT NULL DEFAULT (newid())
Contact Name nvarchar (200)

Contact_Company table
id ([uniqueidentifier] NOT NULL DEFAULT (newid())
contact_id [uniqueidentifier] NOT NULL,
company_id [uniqueidentifier] NOT NULL,


In addition, the excel file will contain the company name more than once (for every contact person in company new row with company name).
I need to insert into table Company the company only once.
I then need to insert the Contact details into the table Contact
Finally, i need to insert into Contact_Company table both the company_id and contact_id

Problems:
-How do i insert into Company table the company only once from excel?
-How do i insert into Contact_Company the correct contact_id and company_id so that the right contact person will be assigned to the company?

Thanks for the help




Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

View 3 Replies View Related

Import From Excel To More Than One Table

Feb 8, 2008

Hi,

I have a excel file that contains some contact information and includes the following columns:
Date, Name, Address, Zip, City and phone

In the db I have 2 tables that I need to insert into, the statment of the first table is:

CREATE TABLE [TMsalg].[SQLUser].[tbl_Customer] (
[CustomerID] int NOT NULL,
[Name] varchar (50) NULL,
[Adress] varchar (100) NULL,
[ZipCode] varchar (50) NULL,
[City] varchar (50) NULL,
[Phone] varchar (50) NULL
)

and the other statment is:
CREATE TABLE [TMsalg].[dbo].[Order_Ernering] (
[OrderID] int NOT NULL,
[Customer_id] int NULL,
[Name] nvarchar (100) NULL,
[Adress] varchar (100) NULL,
[ZipCode] varchar (10) NULL,
[City] varchar (100) NULL,
[Phone] varchar (10) NULL,
)

Problems:
-How do i insert into tbl_Customer table the custom only once from excel?
-How do i insert into Contact_Company the correct customer_id and company_id?

Thanks for the help

View 4 Replies View Related

Import Data From Excel-Sheet Via OleDb In VB.Net - How To Get A Columns Data As String?

Oct 25, 2007

Hello,

i want to import data from an excel sheet into a database. While reading from the excel sheet OleDb automatically guesses the Datatype of each column. My Problem is the first A Column which contains ~240 Lines. 210 Lines are Numbers, the latter 30 do contain strings. When i use this code:







Code BlockDim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & conf_path_current & file_to_import & ";Extended Properties=""Excel 8.0;HDR=NO"""
Dim oConn As New OleDb.OleDbConnection(sConn)
Dim cmd1 As New System.Data.OleDb.OleDbCommand("Select * From [Table$]", oConn)
Dim rdr As OleDb.OleDbDataReader = cmd1.ExecuteReader
Do While rdr.Read()
Console.WriteLine(rdr.Item(0)) 'or rdr(0).ToString
Next




it will continue to read the stuff till the String-Lines are coming.
when using Item(0), it just crashes for trying to convert a DBNull to a String, when using rdr(0).ToString() it just gives me no value.

So my question is how to tell OleDB that i want that column to be completly read as String/Varchar?

Thanks for Reading

- Pierre from Berlin


[seems i got redirected into the wrong forum, please move into the correct one]

View 1 Replies View Related

Transact SQL :: Excel Data Import Truncate Data Length To 255

Jul 29, 2015

I am trying to import data from an excel Sheet to SQL Database using OPENROWSET. After import I found that all the cells containing data of more than 2000 length got truncated to  255 characters only. I tried finding the solution and found that We need to have the data with length more than 255 in first 8 rows of Excel sheet. It worked for me also. But In real scenario the data that I cant do the manual work on excel. I tried out with Dot Net utility and SSIS package also but the truncation is still the issue.

INSERT into tmp_Test
SELECT
*
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel
12.0;Database=D:Book1.xlsx', [Sheet1$])

View 9 Replies View Related

How To Import Data From Excel Into MS SQL In .Net?

Jun 15, 2007

Hi, I'm building a web application in VB.NET 1.1 where users will upload Excel files at this webpage and the web application will transfer the data from the uploaded Excel file into MS SQL 2000. There are around 600-700 records and about 56 columns in the Excel file which is to be uploaded daily. There will be a few different files which I need to implement for as well.
 I've sourced for and tried alot of methods. But either they can't satisfy my requirements or they just can't simply work.
- Most simple and direct way I've tried is creating a oledb connection to the Excel file in the following codes...
Function TestUploadData1(ByVal vFile As String) As String    Dim Oleda As System.Data.OleDb.OleDbDataAdapter    Dim Olecn As System.Data.OleDb.OleDbConnection    Dim dt1 As DataTable
   Olecn = New System.Data.OleDb.OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & vFile & ";" & _ "Extended Properties=Excel 8.0;HDR=Yes")    Olecn.Open()
   Dim ExcelCommand As New System.Data.OleDb.OleDbCommand("SELECT INTO [ODBC;Driver={SQL Server};Server=(local);Database=dbSSC;Trusted_Conn ection=yes].[tblOutstanding] FROM [Report$];", Olecn)    ExcelCommand.ExecuteNonQuery()
   Olecn.Close() End Function
But from the above codes I kept getting the error "Could not find installable ISAM." at the line Olecn.Open(). I've tried to set the registry to C:WindowsSystem32msexcl40.dll but to no avail...
- I've tried another method using the OpenRowSet in the following codes Function TestUploadData2(ByVal vFile As String) As String    Dim cn As SqlConnection    Dim cm As SqlCommand    Dim strSQL As String cn = New SqlConnection("server=localhost; user ID=accessSSC; password=accessSSC541; database=dbSSC")
   cn.Open()
   strSQL = "INSERT INTO tblOutstanding SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=" & vFile & ";HDR=Yes','SELECT * FROM [Report$]')"    cm = New SqlCommand(strSQL, cn)    cm.ExecuteNonQuery()
   cn.Close() End Function
For the above codes, I kept getting the error "Ad hoc access to OLE DB provider 'Microsoft.Jet.OLEDB.4.0' has been denied. You must access this provider through a linked server." at the line cm.ExecuteNonQuery() and I've tried to disable the Ad Hoc settings in the registry and tried to create a link server but to no avail as well...
- I've tried DTS but I'd need to DTS package to run whenever the users upload a file. Is there an easy way that I can run the designated DTS package to run through my .Net web application?
Any help would be deeply appreciated. Thanks & Regards, Keith Chang

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved