Monday, July 16, 2007

Export more than 255 characters into Excel by OLEDB

I create a excel using ole db provider, like below

string connString = "Data Source=" + fullPath + "; Provider=Microsoft.Jet.OLEDB.4.0;    Extended Properties=Excel 8.0;";

OleDbConnection myConn=new OleDbConnection(connString);
OleDbCommand myCommand=new OleDbCommand();
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment string )";

// connect an excel file, if this file doesn't exist, it will be created
myConn.Open();
// create a workbook in this file
myCommand.ExecuteNonQuery();


The problem is when import more than 255 characters into Excel, error occurs:

OLEDBException: The field is too small to accept the amount of data you attempted to add.....

This is because string in Excel has the limitation of 255 characters. To work around this, change the datatype to memo

myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment memo)";

Sunday, July 8, 2007

参观小鹰号航母

7月5日,米国小鹰号航母到达悉尼.停港5日.这大好机会不能错过.周日虽然下午开始阴雨绵绵.但还是携妻先来到Opera House, 穿过植物园,足足在风里雨里走了3公里,终见此庞然大物。

从树下探出头来:


终见全貌:



指挥塔上天线高耸:



战机密布舰尾:



预警机火眼金睛:



原来这家伙编号是63:



此次到访不对公众开放。虽然看到"No Public Tour"的牌子,还不死心问了下米国大兵。那大兵指了指牌说Never。另一个大兵安慰下说:May be next time. 就把我们打发了.遗憾,无法上船看个究竟。