Hi, I'm trying to display an excel file inside the application datagridview using this code...
Java
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?)
tommy20 pointsPosted Feb 9, 2009, 10:41 PM EST
tommy20 pointsPosted Feb 9, 2009, 11:52 PM EST
got it working with the following 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$A2:O33]", oledbConn); OleDbDataAdapter oleda = new OleDbDataAdapter(); oleda.SelectCommand = cmd; DataSet ds = new DataSet(); oleda.Fill(ds); dataGridView1.DataSource = ds.Tables[0].DefaultView; //dataGridView1.DataBind(); oledbConn.Close(); }Is there a way to make the excel file read-only and uneditable in the application?