locked
Move Data from Exvel to sql table RRS feed

  • Question

  • Hi everyone:

    I used to have visual studio 2012 and I could copy Excel data then drop it into a sql table in visual studio.  I tried writing code but don't know the connect string for office 2016, I keep getting error about the connection being wrong. system.data.oledb.oledbexception 'could not find installable isam.'  But I would rather just copy and paste the data from excel to table.

    thx JereTheBear

    Monday, October 29, 2018 6:39 PM

Answers

  • Hi JereBerar,

    Please share related code and detailed error message, it will be beneficial to resolve the issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JereBerar Wednesday, October 31, 2018 12:51 AM
    Tuesday, October 30, 2018 5:11 AM

All replies

  • Hello,

    Can you please describe 

    • Data types for each column in the Excel WorkSheet?
    • Do those data types have matching data types in SQL-Server table?
    • How many columns are there in the Excel WorkSheet?
    • How many rows of data?
    • Does it have to be done in code? If not consider using SSMS (SQL-Server Management Studio) and follow the instructions here.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, October 29, 2018 11:23 PM
  • Hi JereBerar,

    Please share related code and detailed error message, it will be beneficial to resolve the issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JereBerar Wednesday, October 31, 2018 12:51 AM
    Tuesday, October 30, 2018 5:11 AM
  • try with 

    System.Data.OleDb.OleDbConnection


    Tuesday, October 30, 2018 6:22 AM
  • Hi I fixed the issue with a Foxlearn video seen below.  Now I want to use linq to sql and place the datagridview data into the sql Table Stats.  I have my work cut out for me.  Thanks for responding.

    JereTHeBear

    C# Tutorial - How to read an excel (.xls/.xlsx) file | FoxLearn

    https://www.youtube.com/watch?v=JlzzdB3K-1M

    Wednesday, October 31, 2018 12:08 AM
  • Hi I fixed the issue with a Foxlearn video seen below.  Now I want to use linq to sql and place the datagridview data into the sql Table Stats.  I have my work cut out for me.  Thanks for responding.

    JereTHeBear

    C# Tutorial - How to read an excel (.xls/.xlsx) file | FoxLearn

    https://www.youtube.com/watch?v=JlzzdB3K-1M

    Wednesday, October 31, 2018 12:08 AM
  • Hi I fixed the issue with a Foxlearn video seen below.  Now I want to use linq to sql and place the datagridview data into the sql Table Stats.  I have my work cut out for me.  Thanks for responding.

    JereTheBear

    C# Tutorial - How to read an excel (.xls/.xlsx) file | FoxLearn

    https://www.youtube.com/watch?v=JlzzdB3K-1M

    Wednesday, October 31, 2018 12:09 AM
  • Here is the code to get data from excel into a database.
    using System;
    using System.Data;
    using System.Linq;
    using System.Windows.Forms;
    using System.IO;
    using Excel;
    
    namespace FoxLearnTry2
    {
        public partial class Form1 : Form
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();  public Form1()
            {
                InitializeComponent();
               
            }
            
            DataSet Result;
            private void btnOpen_Click(object sender, EventArgs e)
            {
                using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xls", ValidateNames = true })
                {
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
                        IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(fs);
                        reader.IsFirstRowAsColumnNames = true;
                        Result = reader.AsDataSet();
                        cboSheet1.Items.Clear();
                        foreach (DataTable dt in Result.Tables)
                            cboSheet1.Items.Add(dt.TableName);
                        reader.Close();
                    }
                }
            }
    
            private void cboSheet1_SelectedIndexChanged(object sender, EventArgs e)
            {
                dataGridView.DataSource = Result.Tables[cboSheet1.SelectedIndex];
                
            }
        }
    }

    Wednesday, October 31, 2018 5:14 PM