Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Looking for an example

Last post 08-25-2008 10:43 by [Infragistics] Sung Kim. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 08-15-2008 9:27

    • swendell
    • Not Ranked
    • Joined on 08-15-2008
    • Points 45

    Looking for an example

    Any example code to read from Excel into my database / dataset

    We receive database exports from another application in Excel format that I need to import into my application's database

    • Post Points: 20
  • 08-15-2008 9:50 In reply to

    Re: Looking for an example

    string strFilePath = this.MapPath(".") + "\\Workbook.xls";
            string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
            System.Data.OleDb.OleDbConnection cnCSV = new System.Data.OleDb.OleDbConnection(strConnectionString);
            cnCSV.Open();
            System.Data.OleDb.OleDbCommand cmdselect = new System.Data.OleDb.OleDbCommand();
            if (true)
            {
                cmdselect.CommandText = "SELECT * FROM [Sheet1$A1:C6]";
                cmdselect.Connection = cnCSV;
            }
            System.Data.OleDb.OleDbDataAdapter daCSV = new System.Data.OleDb.OleDbDataAdapter();
            daCSV.SelectCommand = cmdselect;
            DataTable dtCSV = new DataTable();
            daCSV.Fill(dtCSV);

            cnCSV.Close();
            daCSV = null;
           

    The code above should read in an excel file into ur datatable.  You will have to change the select command for your purposes.

    • Post Points: 20
  • 08-20-2008 19:43 In reply to

    • swendell
    • Not Ranked
    • Joined on 08-15-2008
    • Points 45

    Re: Looking for an example

    1.The amount of data is not always the same that I need to import so I do not know the exact range, can we somehow select all the rows with data?

    2. the other issue is the date format understood by MYSQL is not the same as the excel date format.... So I need to reformat so it will be understood by MySql when I import

     

    • Post Points: 20
  • 08-25-2008 10:43 In reply to

    Re: Looking for an example

    For the first question, I believe you can just remove the cell range and it will import the entire sheet.

    I do not know the answer to the second question but here is a link to an article that gives an end to end solution:

    http://aspnet.4guysfromrolla.com/articles/031208-1.aspx

     

    • Post Points: 5
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems