2009年11月17日 星期二
C# 的 Decimal 小數點很麻煩...
2009年11月9日 星期一
Postgresql Changing a Column's Data Type
Changing a Column's Data Type
To convert a column to a different data type, use a command like:
ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);
This will succeed only if each existing entry in the column can be converted to the new type by an implicit cast. If a more complex conversion is needed, you can add a USING clause that specifies how to compute the new values from the old.
PostgreSQL will attempt to convert the column's default value (if any) to the new type, as well as any constraints that involve the column. But these conversions might fail, or might produce surprising results. It's often best to drop any constraints on the column before altering its type, and then add back suitably modified constraints afterwards.
2009年9月16日 星期三
.NET 如何加密一字串,只讓執行加密的電腦才能解密。
public static string Protected(string password)
{
if (string.IsNullOrEmpty(password)) return string.Empty;
byte[] plain = Encoding.UTF8.GetBytes(password);
string key = "key";
byte[] cipher = ProtectedData.Protect(plain,
Encoding.UTF8.GetBytes(key),
DataProtectionScope.CurrentUser);
return Convert.ToBase64String(cipher);
}
public static string UnProtected(string base64String)
{
if (string.IsNullOrEmpty(base64String)) return string.Empty;
string key = "key";
byte[] cipher = Convert.FromBase64String(base64String);
byte[] plain = ProtectedData.Unprotect(cipher,
Encoding.UTF8.GetBytes(key),
DataProtectionScope.CurrentUser);
return Encoding.UTF8.GetString(plain);
}