January 11, 2005

Filtering by number in DataView.RowFilter

Since I unsuccessfully Googled for this answer, maybe this entry will help out someone else... :)

Given a string variable named quxx, that falls in the set of [A-Z,#,ALL]:

I wanted to use the DataView RowFilter property to filter data for use in a custom alphanumeric paging control (All, A-Z, and Numbers). The RowFilter expression for the A-Z characters was very straightforward:
dataView.RowFilter = string.Format("{0} LIKE '{1}%'", dataView.Table.Columns[0].ColumnName, quxx);

So, extending that to filter on things that start with a number, I looked at the TSQL syntax, figuring it would be similar and tried:
 dataView.RowFilter = string.Format("{0} LIKE '[0-9]%'", dataView.Table.Columns[0].ColumnName, quxx);
, but got an invalid expression exception.

The way I solved it was to use SubString on the first character in the string (note it is one-based and not zero-based):

dataView.RowFilter = string.Format("SUBSTRING({0}, 1, 1) IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)", dataView.Table.Columns[0].ColumnName, quxx);

Thanks http://www.whoisjake.com for the alphanumeric pager control code :)

January 03, 2005

Favorites from TAoW Calendar, 2004

I was sick of saving the little tear-offs, so they became a blog entry instead. The items below were my favorites from Quotes from Sun-Tzu - The Art of War - 2004 Calendar. I realize regurgitating what others write is not usually interesting or blogworthy, but I chose to make an exception this time!

Enjoy the wisdom! :)

  • Those whose upper and lower ranks have the same desire are victorious. Chapter 3: “Planning the Attack”

  • Once your basic mind is settled, you should just tune and order it, making it calm and stable, undisturbed by events, not deluded by prospects of gain. Chapter 7: “Armed Contest”

  • The lives of the people and the order of the nation are in the charge of the generals. The difficult of finding good leadership material is a perennial problem. Chapter 2: “On Waging Battle”

  • Give out rewards that are not in the rules, give out directives that are not in the code.

  • If the people are treated with benevolence, faithfulness and justice, then they will be of one mind and will be glad to serve. Chapter 1: “On Assessments”

  • Harmony among people is the basis of the way of military operations: the right weather and an advantageous position help. Chapter 1: “On Assessments”

  • The question regarding political leadership is who is able to win the hearts of the people. Chapter 1: “On Assessments”

  • Invincibility is on oneself, vulnerability is in the opponent. Chapter 4: “Formation”

  • Glean from rich fields, and the armies will have enough to eat. Take care of your health and avoid stress, consolidate your energy and build up your strength. Maneuver your troops and assess strategies so as to be unfathomable. Chapter 11: “The Nine Kinds of Terrain”

  • Therefore, I have heard of military operations that were clumsy but swift, but I have never seen one that was skillful and lasted a long time. It is never beneficial to a nation to have a military operation continue for a long time. Chapter 2: “On Waging Battle”

  • Adaptation means not clinging to fixed methods, but changing appropriately according to events, acting as is suitable. Chapter 8: “Adaptation”

  • Do something for or against them, making opponents turn their attention to it, so that you can find out their patterns of aggressive and defensive behavior. Chapter 6: “Emptiness and Fullness”

  • If you use the enemy to defeat the enemy, you will be strong wherever you go.

  • What is orthodox for you, cause opponents to see as unorthodox: what is unorthodox for you, cause opponents to see as orthodox. Chapter 5: “Strategic Advance”

  • Those whose upper and lower ranks have the same desire are victorious. Chapter 3: “Planning the Attack”

  • If you make it clear what is to be rewarded and what punished, make your directives reliable, keep your machines in good repair, train and exercise your officers and troops, and let their strengths be know so as to overcome the opponent psychologically. This is considered very good. Chapter 3: “Planning the Attack”

  • So unless your heart is wide open and your mind is orderly, you cannot be expected to adapt responsively without limit. Dealing with events unerringly, facing great and unexpected difficulties without upset, calmly handling everything without confusion. Chapter 7: “Armed Contest”

  • When the army is old, the soldiers are lazy, and the discipline and command are not unified. This is an opponent that has already lost. Chapter 4: “Formation”

  • Generals in the field must already be acquainted with all the sciences of warfare before they can command their own soldiers and assess battle formations. Chapter 3: “Planning the Attack”

  • Good warriors make others come to them, and do not go to others. This is the principle of emptiness and fullness of others and self. When you introduce opponents to come to you, then their force is always empty: as long as you do not go to them, your force is always full. Attacking emptiness with fullness is like throwing stones on eggs – the eggs are rue to break.

  • When you are spending a great deal of money on a military operation, if the army is out in the field too long, your budget will not be enough to cover the expense.

  • Knowledge that does not go beyond what the generality knows is not really good.