Click here to Skip to main content
15,885,760 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
import excel dsta to databse ,I use the code in link:


http://www.dotnetspider.com/resources/42912-Read-Excel-Data-Show-GridView-asp-net.aspx[^]


but here there is no connection code and table specification .I think it is in webconfig.How to do this .
Any one please help me.
Posted
Comments
[no name] 23-Aug-12 4:00am    
You should search it first, there are many question like yours, even in CodeProject.
http://www.codeproject.com/Answers/392693/how-to-import-excel-into-database.aspx#answer1

Perhaps this article would help
SQL Import Data from Excel[^]
 
Share this answer
 
 
Share this answer
 
DataTable data = new DataTable();
 string ExtraConnection = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openExcelFile.FileName + ";Extended Properties=\"Excel 8.0;IMEX=1;HDR=" + "YES" + "\"");

private void InsertToDataTable(string ExtraConnection)
     {

         using (OleDbConnection connection = new OleDbConnection(@ExtraConnection))
         {

             OleDbCommand command = new OleDbCommand("SELECT * FROM " + txtSheet.Text, connection);
             command.CommandTimeout = 20;
             connection.Open();
             OleDbDataAdapter SDA = new OleDbDataAdapter(command);
             OleDbCommandBuilder SCB = new OleDbCommandBuilder(SDA);
             DataSet m_DataSet = new DataSet();
             SDA.Fill(m_DataSet);
             connection.Close();
             foreach (DataTable table in m_DataSet.Tables)
                 foreach (DataRow row in table.Rows)
                     data.Rows.Add(row.ItemArray);


         }}

C#
using (SqlConnection connection = new SqlConnection(@"Data Source=pyton-exploit;Initial Catalog=SchoolManagement;User ID=AliAsadi;Password=visualc#2010@#"))
         {

             connection.Open();
             using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
             {
                 
                     bulkCopy.DestinationTableName = "tblTeacher";
                     bulkCopy.WriteToServer(data);
                     
                     lblSave.ForeColor = System.Drawing.Color.Green;
                 }}



Load Data from excel and write "DataTable" to SQL Server Table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900