2
Reply

Displaying Excel file in apllication.

tommy

tommy

Feb 9 2009 2:40 AM
2.1k

Hi, I'm trying to display an excel file inside the application datagridview using this code...

try
        {
            string connString = @"provider=Microsoft.Jet.OLEDB.4.0;data source=C:\Documents and Settings\Desktop\workbooktest.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

            OleDbConnection oledbConn = new OleDbConnection(connString);
            oledbConn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [location$]", oledbConn);
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            oleda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            oleda.Fill(ds);
            GridView.DataSource = ds.Tables[0].DefaultView;
            GridView.DataBind();
            oledbConn.Close();
        }

but this compiling error kept coming up...

'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?) 


Answers (2)