C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Excel sheet to DataGrid.... plz urgent.....


Posted Date: 25 Jul 2006      Total Responses: 1

Posted By: AnnyG       Member Level: Gold     Points: 2


How to bind the data from Excel Sheet to DataGrid......... plz explain with example........



Responses

Author: chandra sekhar    25 Jul 2006Member Level: GoldRating:     Points: 2
hi
by using OleDbConnection, we can connect to Excel sheet.
in this case, excel sheet act as SQL Server. that means we can write select, update query


Author: Pritam Baldota    25 Jul 2006Member Level: GoldRating:     Points: 2
you can use oledb connection and excel act as database.


Author: BRUCE DHARA    01 Aug 2006Member Level: BronzeRating:     Points: 2
Hey Anny,

I understand your urgency, well I am sending you the quick & dirty way of doing it. Ofcourse there are nerds out there who will post 10 different responses to point out deficiencies in my code but here it is :

Import these namespaces:

using System.Data;
using System.Data.OleDb;
using Microsoft.Office.Interop.Excel;

Insert this code bit into Load even of your form :

try
{
// Put user code to initialize the page here
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("\\projectfolder\\YourEXCEL.xls")+";Extended Properties=\"Excel 8.0;IMEX=1;HDR=YES;\"";

OleDbConnection objConn=new OleDbConnection(sConnectionString);
OleDbCommand oCmd=new OleDbCommand("SELECT * FROM [Sheet1$]", objConn); //Replace Sheet1 with your excel form's sheet name, append the $ the sign in the end.

objConn.Open();
//ddgXls is the name of the datagrid
ddgXls.DataSource=oCmd.ExecuteReader();
ddgXls.DataBind();
objConn.Close();
}

catch(Exception ex)
{
Response.Write("ERROR:" +ex.Message.ToString());
Response.Write(ex.StackTrace.ToString());
}
}
//Make sure you add your assembly reference to Microsoft Office 8/0/11, leave the version in the connection string as Excel 8.0 else you will get ISAM installer not found error which will take you to a whole new world of debugging w.r.to registry keys etc.

If you get an ISAM error, dont panic. Just make sure your connection string is as described & if the problem still persists check msdn for ISAM Installer Error.

Hope this helps..

Bruce M Dhara


Post Reply
You must Sign In to post a response.
Next : upload website which created on vs2005
Previous : Info Window Problem
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

masks masks masks

Contact Us    Privacy Policy    Terms Of Use