SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 Other Development Tools
 inserting excel rows into SQL SERVER 2005
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

emyk
Yak Posting Veteran

50 Posts

Posted - 04/04/2012 :  23:07:06  Show Profile  Reply with Quote
I am working on excel spreadsheet upload process where users export their data via macro VBA into SQL SERVER 2005.

So far I am able to import data from the SQL server into an execl but I am being challenged with writing excel data into SQL SERVER database:

Here is what I am working on
Sub Connect2SQLXpress()

Dim oCon As ADODB.Connection
Dim oRS As ADODB.Recordset

Set oCon = New ADODB.Connection
oCon.ConnectionString = "Driver={SQL Native Client};Server=myserver;Database=DB; Trusted_Connection=yes;"
oCon.Open

Set oRS = New ADODB.Recordset
oRS.ActiveConnection = oCon
oRS.Source = "insert into table (ID,Name,State,Code) VALUES (Columns("A":"B":"C":"D"))"


oRS.Open


oRS.Close

oCon.Close

If Not oRS Is Nothing Then Set oRS = Nothing
If Not oCon Is Nothing Then Set oCon = Nothing
MsgBox "All done!"

End Sub

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/04/2012 :  23:21:29  Show Profile  Reply with Quote
why not use OPENROWSET or export import wizard for this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 04/17/2012 :  03:51:08  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Webtalk
Starting Member

2 Posts

Posted - 10/11/2012 :  00:53:15  Show Profile  Reply with Quote
I've learn some excellent stuff here.
unspammed
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
2005 Posts

Posted - 10/11/2012 :  01:52:43  Show Profile  Visit jackv's Homepage  Reply with Quote
1) Powershell is very useful in these circumstances
2) Another more manual way is , generate the INSERT staments and run as a script : http://www.sqlserver-dba.com/2012/01/sql-server-generate-sql-insert-from-excel.html

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000