Thursday, March 18, 2010

SPOILERS!

http://tips.blogdoctor.me/2007/11/create-spoilers-in-blog-posts.html Used this link to have spoilers in one of my blogs.

Saturday, March 6, 2010

Import Excel Sheet into a .NET C# page

I got my idea from here
http://www.java2s.com/Code/ASP/ADO.net-Database/LoaddatafromExceldatasourceC.htm
It actually worked beautifully, I read it straight into a gridview now I can deal with the data normally

protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Book1.xls; Extended Properties=""Excel 8.0;HDR=Yes"";";
string CommandText = "select * from [Sheet1$]";

OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbCommand myCommand = new OleDbCommand(CommandText, myConnection);

myConnection.Open();

GridView1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataBind();

myConnection.Close();
}