Import image from excel to datatable.

Last post 08-28-2009 9:24 AM by sonu. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 08-28-2009 3:18 AM

    • shahid13384
    • Top 50 Contributor
    • Joined on 06-09-2008
    • United States of Mehsana
    • Wannabe Slacker
    • Points 563

    Import image from excel to datatable.

     I do have an excel file(excel 2007) which contain the record of the students. each record contain one field call PHOTO that holds image. now i wants to read that excel file every thing goes fine with other columns but PHOTO columns is not read. its returns null. any idea...

     

    Thanks & Regards


    The trouble with the world is that the stupid are sure and the intelligent are full of doubt.

    Shahid Hussain Shaikh
    Filed under: , , , ,
  •  Advertisement

    Featured Advertisement

     
  • 08-28-2009 7:43 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Import image from excel to datatable.

    How are you reading the excel sheet?

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
    Filed under: ,
  • 08-28-2009 9:12 AM In reply to

    • shahid13384
    • Top 50 Contributor
    • Joined on 06-09-2008
    • United States of Mehsana
    • Wannabe Slacker
    • Points 563

    Re: Import image from excel to datatable.

     private DataTable GetDataTable(string sSheetName, string excelFile)

        {

            OleDbConnection objConn = null;

            System.Data.DataTable dt = null;

            try

            {

                // Connection String. Change the excel file to the file you

                // will search.

                string file = ConfigurationManager.AppSettings["Upload"].ToString() + excelFile;

                String connString = "Provider=Microsoft.ACE.OLEDB.12.0;" +

                    "Data Source=" + file + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";

                // Create connection object by using the preceding connection string.

                objConn = new OleDbConnection(connString);

                // Open connection with the database.

                objConn.Open();

                string strConString = "SELECT * FROM [" + sSheetName + "]";

                OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn);

                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

                // Pass the Select command to the adapter. 

                objAdapter1.SelectCommand = objCmdSelect;

                // Create new DataSet to hold information from the worksheet. 

                DataSet ds = new DataSet();

                objAdapter1.Fill(ds);

                if (ds != null && ds.Tables.Count > 0)

                {

                    dt = ds.Tables[0];

                    if (dt == null)

                    {

                        return null;

                    }

                    else return dt;

                }

                return null;

            }

            catch 

            {

                return null;

            }

            finally

            {

                // Clean up.

                if (objConn != null)

                {

                    objConn.Close();

                    objConn.Dispose();

                }

                if (dt != null)

                {

                    dt.Dispose();

                }

            }

        }

    Thanks & Regards


    The trouble with the world is that the stupid are sure and the intelligent are full of doubt.

    Shahid Hussain Shaikh
  • 08-28-2009 9:24 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Import image from excel to datatable.

    Have you tried the aspose excel component instead? Its free (if you just want to read the file) ;)

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
    Filed under: , ,
Page 1 of 1 (4 items)