473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to insert a Excel data in SQL server using ASP

hi
i want to insert a data into a SQL Server from Excel file using ASP
plz help me
Jun 4 '07 #1
11 10659
hi
i want to insert a data into a SQL Server from Excel file using ASP
plz help me
===
Hi

I have the same question too. But I tried using DTS to import the excel file to SQL, and while selecting the source file driver- it gives and error that its an invalid driver selected. I used excel 5/4/3, 97-2000, all options mentioned- but didnt work

-Tanya
Jun 4 '07 #2
jhardman
3,406 Expert 2GB
Tanya, (and this goes for Yogesh, too)

Show me what you have so far. Also, what is the data format of the excel file? How do you have the tables organized?

Jared
Jun 4 '07 #3
Tanya, (and this goes for Yogesh, too)

Show me what you have so far. Also, what is the data format of the excel file? How do you have the tables organized?

Jared

Hi Jared, Thanks for your interest.
Here is what I have to do:
I have four tables, as posted in my recent question- sql1,sql2,sql3,sql4- which are all excel files. Data inside these tables are charecters, intergers etc...
like email id, account number, names etc...
Now i have copied these files to the sql server desktop and launched dts wizard
It asked me to choose files...in data source type- selected as excel 3.0
and clicked on next-- it went to destination type- selected our sql server...
it then says invalid input data source connection type....
So- I am not sure, if there is any other way of exporting all the excel files to sql ..server 2000. I saw some code in google for moving data from excel to sql, but where should it be run, on server side??
please suggest
Tanya
Jun 4 '07 #4
jhardman
3,406 Expert 2GB
Tanya,

Yes, There are several methods to copy them over. You can use asp, but a db manager should do a better job.

Anyway, don't connect to the excel file with dns, just specify a driver in your asp like this:
Expand|Select|Wrap|Line Numbers
  1. Set objConn = Server.CreateObject("ADODB.Connection")
  2. objConn.open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\myspreadsheet.xls; Extended Properties=Excel 8.0;"
  3. set objRS = server.createObject("ADODB.recordset")
  4. objRS.open objConn, "SELECT * FROM sql1"
Some people create new tables and new DBs using asp, but I would not recommend it. at very least, make empty db tables with the correct field names.

Now you should be able to open a connection and recordset for the SQL db at the same time, but for that one you will need a DNS entry. (this is a slightly different topic and steps in making one depend on your OS. If you need help with that, let me know)
Expand|Select|Wrap|Line Numbers
  1. set conn=Server.CreateObject("ADODB.Connection") 
  2. conn.Open "mySQLtable"
  3. set RS = server.createObject("ADODB.recordset")
  4. RS.open conn, "SELECT * FROM sql1", adOpenDynamic, adLockOptimistic
Now you have both dbs open. objRS is the recordset from the excel file, and RS is from the SQL db. Notice I needed to open the sql db dynamically so I could update it. Copy from one to the other like this:
Expand|Select|Wrap|Line Numbers
  1. do until objRS.eof
  2.    RS.addnew
  3.    for each x in objRS
  4.       RS(x) = objRS(x)
  5.    next
  6.    RS.update
  7.    objRS.moveNext
  8. loop
the do loop scrolls through each record in the excel file. It creates a new record in the SQL db, populates each field as it is in the excel file then updates, and moves to the next row of the excel table. This should work pretty straight-forward except there are a lot of things that can go wrong. SQL server does not accept the same formats as excel (I've always noticed boolean fields -True or false- give it trouble). anyway, try this. If it doesn't work let me kjnow and I will see if I can work thru the errors.

Jared
Jun 5 '07 #5
Tanya, (and this goes for Yogesh, too)

Show me what you have so far. Also, what is the data format of the excel file? How do you have the tables organized?

Jared
hi jared
i have a excel file in that i contain the attendance of employee (employeeid,name,logindate,time,logoutdate etc) and in SQL Server i have one table hrms_attends and same fields i can created hear a now i want to add excel contain in SQL table plz help me
Yogesh
Jun 5 '07 #6
jhardman
3,406 Expert 2GB
hi jared
i have a excel file in that i contain the attendance of employee (employeeid,name,logindate,time,logoutdate etc) and in SQL Server i have one table hrms_attends and same fields i can created hear a now i want to add excel contain in SQL table plz help me
Yogesh
so the fields in both tables are named the same? Then the example I outlined below for tanya should work. Try it and let me know.

Jared
Jun 5 '07 #7
hi sir
i can write the following code

set obj=Server.CreateObject ("Adodb.Connection")
obj.Open "Provider=Microsoft.Jet.OLEDB.4.0;Excel 8.0;Database=D:\March_2007_attendance.xls;"
set objrs=Server.CreateObject ("ADODB.Recordset")
Sql="select * from [March_2007_attendance$]"
bjrs.Open Sql,obj



set RS = server.createObject("ADODB.recordset")
RS.open cnn, "SELECT * FROM HRMS_Attends1", 1

do until objrs.EOF
'response.Write "in loop"
'response.End
rs.AddNew
for each x in objrs
rs(x)=objrs(x)
next
rs.Update
objrs.MoveNext
loop


=========
but it can show the error message like

Microsoft JET Database Engine error '80040e37'

The Microsoft Jet database engine could not find the object 'March_2007_attendance$'. Make sure the object exists and that you spell its name and the path name correctly.

And March_2007_attendance$ is my Excle file and Work sheet name
Jun 5 '07 #8
Hello jhardman,

I have this code pattered from this forum

Set objConnEx = Server.CreateObject("ADODB.Connection")
objConnEx.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Netroot\WebApp\testprograms\malen\Shuttl e_Service\Attachment\"&FileName&;Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;"
set objRS = server.createObject("ADODB.recordset")
objRS.open objConnEx, "SELECT * FROM tbl_Request"

"SELECT * FROM tbl_Request" - This is my SQL table, my question is
objConnEx is my connection to excel, why it is I have SQL Select statement here on excel connection.

PLease help..THanks
Jun 27 '07 #9
jhardman
3,406 Expert 2GB
"SELECT * FROM tbl_Request" - This is my SQL table, my question is
objConnEx is my connection to excel, why it is I have SQL Select statement here on excel connection.

PLease help..THanks
SQL stands for standard (or possibly structured) query language, it is just a standard way to connect to any db, and you are using excel like a db. Microsoft did not invent SQL, and using the name SQL does not necessarily mean you are connecting to Microsoft's SQL Server.

Jared
Jun 28 '07 #10
pexp
4
Dear Jared,

I was trying to use your code for insertion of excel data into a database but I am getting the following error

*************[Error]*************************
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
************[/Error]*************************

Please help!
----------------------------------------------
Tanya,

Yes, There are several methods to copy them over. You can use asp, but a db manager should do a better job.

Anyway, don't connect to the excel file with dns, just specify a driver in your asp like this:
Expand|Select|Wrap|Line Numbers
  1. Set objConn = Server.CreateObject("ADODB.Connection")
  2. objConn.open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\myspreadsheet.xls; Extended Properties=Excel 8.0;"
  3. set objRS = server.createObject("ADODB.recordset")
  4. objRS.open objConn, "SELECT * FROM sql1"
Some people create new tables and new DBs using asp, but I would not recommend it. at very least, make empty db tables with the correct field names.

Now you should be able to open a connection and recordset for the SQL db at the same time, but for that one you will need a DNS entry. (this is a slightly different topic and steps in making one depend on your OS. If you need help with that, let me know)
Expand|Select|Wrap|Line Numbers
  1. set conn=Server.CreateObject("ADODB.Connection") 
  2. conn.Open "mySQLtable"
  3. set RS = server.createObject("ADODB.recordset")
  4. RS.open conn, "SELECT * FROM sql1", adOpenDynamic, adLockOptimistic
Now you have both dbs open. objRS is the recordset from the excel file, and RS is from the SQL db. Notice I needed to open the sql db dynamically so I could update it. Copy from one to the other like this:
Expand|Select|Wrap|Line Numbers
  1. do until objRS.eof
  2.    RS.addnew
  3.    for each x in objRS
  4.       RS(x) = objRS(x)
  5.    next
  6.    RS.update
  7.    objRS.moveNext
  8. loop
the do loop scrolls through each record in the excel file. It creates a new record in the SQL db, populates each field as it is in the excel file then updates, and moves to the next row of the excel table. This should work pretty straight-forward except there are a lot of things that can go wrong. SQL server does not accept the same formats as excel (I've always noticed boolean fields -True or false- give it trouble). anyway, try this. If it doesn't work let me kjnow and I will see if I can work thru the errors.

Jared
Sep 30 '08 #11
jhardman
3,406 Expert 2GB
Dear Jared,

I was trying to use your code for insertion of excel data into a database but I am getting the following error

*************[Error]*************************
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
************[/Error]*************************

Please help!
----------------------------------------------
The error means one of the data types in the excel file is slightly different than the data type in the database, dates always give me this error if they are in the wrong format, that is why I always suggest using unambiguous date types like "2008-Oct-01".

Anyway, what you need to do first is find the exact location of the error, then you can figure out in what sense the data type is wrong. An easy way to pinpoint the location is to add comments for each line:
Expand|Select|Wrap|Line Numbers
  1.  for each x in objRS
  2.       response.write "<!-- Adding " & x & " -->" & vbNewLine
  3.        RS(x) = objRS(x)
  4.    next
then the last comment lists the field that caused the error. Let me know if you have any other questions or if this helps.

Jared
Oct 1 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
2
by: Mardy | last post by:
Hello I'm working on code to upload an Excel file, read the spreadsheet contents into a datagrid, then ultimately insert each row into a sql server database. Currently I have the file upload...
3
by: hkappleorange | last post by:
I connect to mdb file using the following codes. How should I modify it if I want to connect to Excel instead ? <%@ Import Namespace="System.Data.OleDb" %> <% Dim conAuthors As...
0
by: Mamatha | last post by:
Hi When i clicked a button, i want to insert data from listview in VB.NET to Excel sheet. If you know the solution either above or below is ok for me. I know how to insert from a textfile,but...
8
by: carlospedr | last post by:
I have to insert data from about 30 tables into a single table (Users), to do so i used a cursor and a bit of dynamic sql, this should work fine if the tables have to do the select from had the...
7
Merlin1857
by: Merlin1857 | last post by:
Its great producing data for users to look at in your web pages and generally that is sufficient for their needs but sometimes you may want to supply your user with the data in a form they can...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
1
by: pexp | last post by:
Hello All, I would like to insert/update a database table using excel file. I have a list of products in an excel file. If product exist in a database table tblproduct than it should update the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.