Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
       {
           String str = "Provider=Microsoft.Jet.OLEDB.4.0;" +
          "Data Source=D:\\Book1.xls;" +
          "Extended Properties=Excel 8.0;";

           DataSet d = new DataSet();
           //You must use the $ after the object
           //you reference in the spreadsheet
           OleDbDataAdapter da = new OleDbDataAdapter
           ("SELECT * FROM [Sheet1$]", str);

           //da.TableMappings.Add("Table", "ExcelTest");

           da.Fill(d);
           dataGrid1.DataSource = d.Tables[0].DefaultView;
           dataGrid1.DataBind();
       }



err in line dataGrid1.DataBind(); <<<< error

help me plzzz
Posted
Comments
Dave Kreskowiak 17-Mar-11 10:50am    
So you got an error... Did you stop to think that IT MIGHT BE IMPORTANT THAT YOU TOLD US WHAT THE ERROR IS?!?!?!? It's like taking your car in for service and telling them "It's broke", then walking away. How is anyone supposed to know what the problem is they're looking for??
Yusuf 17-Mar-11 11:16am    
Oh, the garage will be very happy to run all sorts of test to figure out what the problem. But the question is that is the customer willing to foot the bill.

Now when it comes to FREE service, let us leave it there.... :-)
Gonzoox 17-Mar-11 10:59am    
is this urgentzzzzzzzz???
Yusuf 17-Mar-11 11:20am    
Check your da, d, d.Tables[0].DefaultView, dataGrid1 and any other object you may thing is the problem.

You see with out specific error, very hard to take a wild guess.
pankajupadhyay29 17-Mar-11 12:09pm    
Could u provide the error message here?

Use something like EPPlus[^] or Excel Data Reader - Read Excel files in .NET[^]

You can the even expect your code to work on servers where the jet engine is not available like 64-bit windows. Good luck :)

Update
error in line >>>> dataGrid1.DataBind(); is for asp.net DataGrid, not Windows Forms - that's why my answer initally recommended technologies suitable for handling excel spreadsheets in realation to asp.net under IIS. Here is an article on databinding in Windows Forms:
BindingSource and BindingNavigator in C# 2.0[^]

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Albin Abel 18-Mar-11 5:56am    
Correct Point out of error and alternate solutions. Great. 5+
Espen Harlinn 18-Mar-11 5:57am    
Thanks AlbinAbel!
Sergey Alexandrovich Kryukov 18-Mar-11 14:34pm    
Good references and advice, a 5.
--SA
VB
Error   1   '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?) D:\Ex\C#\Test GUI\1\ex\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs   38  23  WindowsFormsApplication3




error in line >>>> dataGrid1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900