Copy data from excel to ms sql
Please support our MS SQL advertiser: Programming Forums
Thread Solved
![]() |
•
•
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:
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
Other Threads in the MS SQL Forum
- 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
•
•
•
•
Views: 949 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)





Linear Mode