Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2006, 10:59 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Fly4High Send a message via Yahoo to Fly4High
Default Importing datas to SQL Server. Need suggestions!

Hi forum,
I have hundreds of Excel spreadsheets, each contain full client detail. I need to import all those data to my SQL Server database into the Client table. But if I import manually one by one it'll take a lot of times to complete importing. I also try EMS Data Import for SQL Server but it not better, still importing one by one spreadsheet and might take more time.
Can anyone suggest me some other ways to import all those datas fast and reliable, or should I create a tool for my own purpose? Pls help, in urgent!
Thanks.

Think as you're someone else, act as the way you are!
 
Old August 1st, 2006, 01:10 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Read about OPENROWSET function.

The basic syntax is this

SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
   'Excel 5.0;HDR=No;IMEX=0;Database=\\seludt2135\c$\documen ts and settings\selupln\desktop\book2.xls', 'select * from [Sheet1$a1:q50]')
--where f1 <> 'a'

If you get unexpected erros, try this for extended error messages
SELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Excel Driver (*.xls)};DBQ=\\seludt2135\c$\documents and settings\selupln\desktop\book2.xls',
    'SELECT * FROM [Sheet1$]')

 
Old August 8th, 2006, 02:10 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to do the same thing. I have a csv file that contains only one column (phone number). There are no headings in the file so the first phone number appears in A1.

I am doing this on my local machine and I got it working with the following code with one exception:
Code:
Private Function ImportLeadFile(ByVal projectfile As String, ByVal sLeadFile As String, ByVal DATABASE As String) As Boolean
        Dim objConn As nsSqlClient.SqlConnection
        Dim ds As New DataSet
        Dim m_strConnection As String = "server=NINEL-D246655F1;Initial Catalog=TimeControl;user id=timeuser;password=timeuser;"

        objConn = New nsSqlClient.SqlConnection
        objConn.ConnectionString = m_strConnection
        objConn.Open()

        ' Make sure the .CSV file exists:
        If File.Exists(sLeadFile) Then
            Try
                ' ------ Load the data from the .CSV file: ----------
                Dim strSQL As String
                strSQL = "Select * " & _
                       " INTO " & DATABASE & ".dbo.[List_staging] " & _
                      "FROM  OPENROWSET('MSDASQL','Driver={Microsoft Text Driver (*.txt; *.csv)}; DEFAULTDIR=C:\VoicenetSQL\project\tampa\Politic\" & projectfile & "; Extensions=CSV; HDR=No;','SELECT * FROM at1008.csv') "

                 Dim objCommand As nsSqlClient.SqlCommand
                objCommand = New nsSqlClient.SqlCommand(strSQL, objConn)

                objCommand.CommandText = strSQL
                objCommand.ExecuteNonQuery()
                objConn.Close()
            Catch ex As Exception
                sResultText = sResultText & "<BR>" & ex.Message
            End Try
        End If
End Function
When the file gets imported into a table the first phone number record is created as a column name. How can I get around this?








Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing multiple text files to sql server db tammyk SQL Server DTS 1 April 25th, 2008 12:07 AM
Importing from SQL Server to test site Aldark SQL Server 2000 4 June 4th, 2007 10:52 PM
Importing data into SQL Server 2005 Express rit01 SQL Server 2005 1 March 22nd, 2007 02:23 PM
Importing Excel to Sql Server dowens3rd ADO.NET 0 March 20th, 2007 03:33 PM
Importing csv file to SQL Server Using VB.Net ninel General .NET 0 August 8th, 2006 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.