| | |
Copy data from excel to ms sql
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Hi, I am trying to copy som data from an excel document that I have on the server into a table in my ms sql server.
I think the problem now is that I am having trouble connecting to the sql server.
I'm using sql server 2005.
You can see the error message here:
http://www.excel.web.surftown.dk/default.aspx
and then click on the button.
This is all the code I have written:
I hope someone can help me with the problem?
Kischi
I think the problem now is that I am having trouble connecting to the sql server.
I'm using sql server 2005.
You can see the error message here:
http://www.excel.web.surftown.dk/default.aspx
and then click on the button.
This is all the code I have written:
MS SQL Syntax (Toggle Plain Text)
USING System; USING System.Collections.Generic; USING System.Linq; USING System.Web; USING System.Web.UI; USING System.Web.UI.WebControls; USING System.DATA.SqlClient; USING System.DATA; USING System.Configuration; USING System.Collections; USING System.Web.Security; USING System.Web.UI.WebControls.WebParts; USING System.Web.UI.HtmlControls; USING System.DATA.Common; USING System.DATA.OleDb; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string excelConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;""", Server.MapPath("database.xls")); USING (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand ("Select ID,Data FROM [Sheet1$]", connection); connection.Open(); USING (DbDataReader dr = command.ExecuteReader()) { string sqlConnectionString = "Data Source=;Initial Catalog=Test;Integrated Security=True"; USING (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "ExcelData"; bulkCopy.WriteToServer(dr); } } } } }
I hope someone can help me with the problem?
Kischi
![]() |
Similar Threads
- transfer contends from database table to excel (C#)
- How to import Excel Sheet data into SQL Server 2003 ???? Stpes. (MS SQL)
- trojans...now nothing opens and I get a paint can't open error (Viruses, Spyware and other Nasties)
- Access database, (MS Access and FileMaker Pro)
- How to print tables in SQL Server 2005 (MS SQL)
- Using Microsoft Excel 10.0 Libary Object -Dang .dlls (C#)
- IE Will Not Open Anymore (Viruses, Spyware and other Nasties)
Other Threads in the MS SQL Forum
- Previous Thread: query for selecting last column from sqldb
- Next Thread: Fulltext Index problems
| Thread Tools | Search this Thread |





