Note that there are some explanatory texts on larger screens.

plurals
  1. POTransfer data from excel to SQL
    primarykey
    data
    text
    <p>I have created a demo for uploading an Excel file to webserver and then copying data from it to SQL server db. It is working perfectly. </p> <p>ASPX Design:</p> <pre><code> &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;span style="color: Red"&gt;*&lt;/span&gt;Attach Excel file &lt;/td&gt; &lt;td&gt; &lt;asp:FileUpload ID="fileuploadExcel" runat="server" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt; &lt;asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Code behind:</p> <pre><code> private String strConnection = "Data Source=Test-PC;Initial Catalog=ExcelMapping;User ID=Test;Password=Test"; protected void Page_Load(object sender, EventArgs e) { } protected void btnSend_Click(object sender, EventArgs e) { //file upload path string path = fileuploadExcel.PostedFile.FileName; fileuploadExcel.SaveAs(Server.MapPath(path)); //Create connection string to Excel work book string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(path) + ";Extended Properties=Excel 12.0;Persist Security Info=False"; //Create Connection to Excel work book OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); //Create OleDbCommand to fetch data from Excel OleDbCommand cmd = new OleDbCommand("Select [lat],[long] from [Sheet1$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); DataSet ds = new DataSet(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); //Give your Destination table name sqlBulk.DestinationTableName = "Test"; sqlBulk.ColumnMappings.Add(0, 1); sqlBulk.ColumnMappings.Add(1, 2); sqlBulk.WriteToServer(dReader); excelConnection.Close(); } } </code></pre> <p>But when I use the same code in an existing application. It gives me error while opening the connection with Excel stating </p> <blockquote> <p>The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine</p> </blockquote> <p>Please suggest me what to do to resolve this. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload