将excel dsta导入数据库 [英] import excel dsta to databse

查看:84
本文介绍了将excel dsta导入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入excel dsta到数据库,我使用链接中的代码:





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





但这里没有连接代码和表格规格。我想它在webconfig中。如何做到这一点。

任何人请帮助我。

解决方案

也许这篇文章会有所帮助

SQL从Excel导入数据 [ ^ ]


< blockquote>试试这篇文章

将数据从Excel导入到SQL Server [ ^ ]


 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 =新的OleDbCommandBuilder(SDA);
DataSet m_DataSet = new DataSet();
SDA.Fill(m_DataSet);
connection.Close();
foreach(m_DataSet.Tables中的DataTable表)
foreach(table.Rows中的DataRow行)
data.Rows.Add(row.ItemArray);


}}



 使用(SqlConnection connection =  new  SqlConnection( @ 数据源= pyton-exploit;初始目录= SchoolManagement;用户ID = AliAsadi;密码= visualc#2010 @#))
{

connection.Open ();
使用(SqlBulkCopy bulkCopy = new SqlBulkCopy(连接))
{

bulkCopy.DestinationTableName = tblTeacher;
bulkCopy.WriteToServer(data);

lblSave.ForeColor = System.Drawing.Color.Green;
}}







从excel加载数据并将DataTable写入SQL Server表


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.

解决方案

Perhaps this article would help
SQL Import Data from Excel[^]


try this article
Import Data from Excel to SQL Server[^]


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);


         }}


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


这篇关于将excel dsta导入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆