Posted by: tzuhsun | October 27, 2009

故事

有没有发觉到,我的 blog 多了一个 “故事” 的页面?

有时候,长篇大论也比不上一个故事。

好的故事,比得上许多长篇大论。

一个故事,不同时候,不同地方,任何人,都可以有新的诠释。

故事动人,或许在此。

你的故事呢?

Posted by: tzuhsun | August 1, 2009

Michael Jackson (1958 – 2009)

电视捞饭(粤),一个很生动的形容词来注释我的孩提时代。

当时电视台(现在也一样)会在两个节目时段中间插播一些 广告或 MTV,说真的,小时候听歌都不太会注意歌词的(现在也一样),插播时段就成了我的休息时间。

`

除了,

Michael Jackson 的 MTV。

`

小小的眼球紧盯着荧幕,恨不得看透每个动作。对这些看起来只有非人类才能做到的舞蹈动作,小小的心灵充满了惊叹与佩服,曾经通过模仿他的舞步来理出头绪,最后得出结论还是 Michael Jackson 最棒。

`

27 – 29.10.1996,默迪卡体育场将举办《历史之旅》演唱会,报章大肆报道,我当时初中二,也凑热闹剪了一篇封路的新闻,幻想着要是有机会去看演唱会这剪报就用得上了。

地图背部地图背部

地图地图

哈哈哈,想不到至今还保存着这个剪报。

`

Michael 走了,我惋惜。

rip.

Posted by: tzuhsun | June 22, 2009

The Word

What is the word?

Refer to previous post, the code is actually refer to a word.
However it is my word, because the word is

TZU

Yeah, it is my word, can see my word now?

Why? look at your keyboard, if you using notebook, get one desktop and back to my blog again, and look at your keyboard one more time.

haha, cheers.

Posted by: tzuhsun | June 4, 2009

Challenge from me

This challenge was came across my mind last week, and I upload it to my MSN for one week.

That will be easy for somebody, and someone may find it hard.

Actually my friend Kelvin already broke the code yesterday since he’d read something similar to this challenge. However I swear that I never refer to any resources or books, it is just something I think is funny so I put it here to crack your head.

:-P :-P:-P

~~~ * ~~~ * ~~~ *~~~

Here come the challenge, try to guess the meanings of the code below:

78952 7895123 7412369

~~~ * ~~~ * ~~~ *~~~

This week hint:

1) 12358 1235789 1478963

2) Think of something relate to me…

3) No more clue, answer will be given directly.

~~~ * ~~~ * ~~~ *~~~
Posted by: tzuhsun | May 28, 2009

Firefox 的 游戏模拟机

几个月前试过很不错的 Firefox plugin,很多都是以前玩过的,

玩到很过瘾下。

夠誇張的 FireFox 附加元件 – 紅白機模擬器

安装步骤就参考上面的 link。

至于可按的 key 有:

[上下左右,CTRL,Z,X],

[8546 (就是上下左右),7,9]

抓一幅图来先睹为快。

Donkey Kong

Donkey Kong

You need to add reference before you start (Refer to my previous post – Rename Field in MS Access Programmatically using ADOX (C#.NET) )

using ADOX;

// Skipped namespace and public class here…

private void btnUpdate_Click(object sender, EventArgs e)
{
   string connString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb;Persist Security Info=False”;
  CatalogClass cat = new CatalogClass();

   cat.let_ActiveConnection(connString)

AddField(cat, “TargetTable”, “Employee_Name_2″, DataTypeEnum.adVarWChar, 50, string.Empty);
}

private void AddField(ADOX.CatalogClass cat, string tableName, string newFieldName, DataTypeEnum varType, int size, string defaultValue)
{
// #1
// cat.Tables[tableName].Columns.Append(newFieldName, varType, size);

ColumnClass col = new ColumnClass();
col.Name = newFieldName;
col.Type = varType;
col.DefinedSize = size;

// Make this field become nullable field.
col.Attributes = ColumnAttributesEnum.adColNullable;

// #2
cat.Tables[tableName].Columns.Append((object)col, DataTypeEnum.adInteger, 0);
// #3 – Assign default value after column appended.
if (!string.IsNullOrEmpty(defaultValue))
{
col.Properties["Default"].Value = defaultValue;
}
}

Issues when using Append() method

Issues when using Append() method

Issues when using Append() method (Refer #1 in source code above):

  1. You only can defines field name, variable type and size for the new field.
  2. New field are not allow NULL when created. (Tested in Access 2003).
  3. You cannot sets default value for new field.

In order to create nullable column with default value,  I use a ColumnClass object – col, and set the necessary properties.

Few things here:

  1. From reference #2, col object need to pass as object type in Append(…) method.
  2. When you pass col object into Append() method, the rest of the arguments in Append(…) actually do NOT overwrite the ‘Type’ and ‘DefinedSize’ properties in col object. So the 2nd argument and 3rd argument is just to fill up the extra places in Append(…).
  3. In reference #3, you only can assign the default value after appended the new field. (Refer to FIX: Cannot Use ADOX to Set Default Value for Column Property)

~~~ [ End ] ~~~

Reference:

  1. Rename Field in MS Access Programmatically using ADOX (C#.NET)
  2. FIX: Cannot Use ADOX to Set Default Value for Column Property

Keyword: ALTER COLUMNS, ALTER TABLE, Microsoft Access

MS Access is a lightweight database and lack of some database feature, for example it does not support the SQL query to rename the field. Therefore we need to workaround to rename the field in MS Access.

MS Access SQL reference: Microsoft Office Access – SQL Reference

Instead I never had VB6 in my PC but only .NET, so I looking for workaround in .NET. Below are the references:

  1. ADO.NET Programmer’s Reference – Chapter 16 – COM Interoperability (Just search for ‘ADOX’ in this article to check for ADOX usage).
  2. How to rename the column name in MS Access table (Reference in VB6, Main source for me to convert ADOX into .NET)

You need to add the ADOX COM reference into your .NET project because we are going to use ADOX to do the trick.

Add ADOX COM Reference from Solution Explorer

Add ADOX COM Reference from Solution Explorer

First you need to to go to Add Reference from Solution Explorer, add Microsoft ADO Ext.2.8 for DDL and Security from COM tab.

Then, use the code below,

using ADOX;

// Skipped namespace and public class here…

private void btnUpdate_Click(object sender, EventArgs e)
{
   string connString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb;Persist Security Info=False”;
  CatalogClass cat = new CatalogClass();
// cat.ActiveConnection = connString <-- Error here
// Cannot assign to cat.ActiveConnection directly.
// Use code at below to assign connection string in C#.

   cat.let_ActiveConnection(connString);

   RenameField(cat, “TargetTable”, “Staff”, “Employee”);

}

private void RenameField(CatalogClass cat, string tableName, string originalFieldName, string newFieldName)
{
   cat.Tables[tableName].Columns[originalFieldName].Name = newFieldName;
}

Run the button btnUpdate_Click to make the trick work, so the field Staff will rename to Employee.

Note that you cannot assign the connection string directly to cat.ActiveConnection since it is not a string object, and I guess it only accept Connection object from ADO. Use cat.let_ActiveConnection(connString) instead.

Micorsoft example on ADOX connection string – PRB: Unhandled Exception When You Set ADO Property to a String in Visual C# .NET

~~~ End ~~~

Upcoming article: Add New Field in MS Access Programmatically using ADOX (C#.Net)

Reference:

  1. Microsoft Office Access – SQL Reference
  2. ADO.NET Programmer’s Reference – Chapter 16 – COM Interoperability
  3. How to rename the column name in MS Access table
  4. http://support.microsoft.com/kb/309047

Keyword:  ALTER COLUMNS, ALTER TABLE, Microsoft Access

Posted by: tzuhsun | April 21, 2009

TryParse – out parameter cannot work with Property

Today I facing the exact situation written in reference #1, I tried to pass the property to TryParse out parameter.

Below is the sample code:

int i;

public int I
{
  get;
  set;
}

int.TryParse(str, out I);   // pass I (not i) as out parameter

But I got this error message:

A property or indexer may not be passed as an out or ref parameter.

Till now I cannot get any satisfactory explanation about this error, however I think the most acceptable answer for now is from reference #2.

The fact that a property looks and feels like a variable is deceiving. When compiled, a property becomes two methods: one for the Getter and one of the Setter. This is why the property fails when you try to use it in TryParse().

Solution is simple, just place the original variable as out parameter.

This question make me need to understand MSIL one day to find out what happen inside there…

Reference:

  1. Mano’s Tech Blog – Different ways to convert string to an integer in C#
  2. Why TryParse Can’t Get Property?

Keyword: Accessor, get,set,getter,setter,error

Posted by: tzuhsun | March 13, 2009

Free and simple diagram designer

I cannot afford Visio, I don’t like to draw in MS Word, and I just need to draw a simple diagram.

I found this Diagram Designer, it is simple and has everything I needs.

(I can’t remember how i found this software, probably from Sourceforge.net, but it is not there anymore, :-p )

The software is straight forward, drag the shape you want and drop it to the canvas, to format the text inside shape, just follow the text formatting code while do it. For example, to show Bold text, just put \BBold\b in the textbox.

There are more features to discover, and you will find it useful.

Software link: http://meesoft.logicnet.dk/

 

~~~ * ~~~

Keyword: UML, Architect, Flowchart, Graph, Design

Posted by: tzuhsun | February 17, 2009

SQL Select random row from table

Reference: SQL to Select a random row from a database table

Quick reference to article above:


-- Select a random row with MySQL:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1

-- Select a random row with PostgreSQL:
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1

-- Select a random row with Microsoft SQL Server:
SELECT TOP 1 column FROM table
ORDER BY NEWID()

-- Select a random row with IBM DB2
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY

-- Thanks Tim

-- Select a random record with Oracle:
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1

Keyword:  random record

Older Posts »

Categories