Posts

MSSQL - Alter Column Data Type

In normally in SQL, syntax for alter table is ALTER TABLE table_name MODIFY column_name data_type Example. ALTER TABLE products MODIFY product_name VARCHAR2(50) But if in MSSQL, you have to use "ALTER COLUMN" instead. ALTER TABLE table_name ALTER COLUMN column_name data_type Example. ALTER TABLE products ALTER COLUMN product_name varchar(50)

C# - AES Encrypt

input: string message, string keycode output: string BASE64String using System.Security.Cryptography; RijndaelManaged aesCipher = new RijndaelManaged(); ASCIIEncoding textConverter = new ASCIIEncoding(); Byte[] iv; aesCipher.KeySize = 128; aesCipher.BlockSize = 128; aesCipher.Mode = CipherMode.ECB; aesCipher.Padding = PaddingMode.Zeros; aesCipher.Key = textConverter.GetBytes(keycode); ICryptoTransform crypto = aesCipher.CreateEncryptor(); Byte[] toEncrypt = textConverter.GetBytes(messg); Byte[] cipherText = crypto.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length); String base64Str = ""; base64Str = Convert.ToBase64String(cipherText);

C# - Server Variable

Example: String _user_agent = Request.ServerVariables["HTTP_USER_AGENT"]; String _all_http = Request.ServerVariables["ALL_HTTP"]; Response.Write("user_agent:" + _user_agent + ","); Response.Write("ALL HTTP:" + _all_http); All Server Variable: ALL_HTTP ALL_RAW APPL_MD_PATH APPL_PHYSICAL_PATH AUTH_PASSWORD AUTH_TYPE AUTH_USER CERT_COOKIE CERT_FLAGS CERT_ISSUER CERT_KEYSIZE CERT_SECRETKEYSIZE CERT_SERIALNUMBER CERT_SERVER_ISSUER CERT_SERVER_SUBJECT CERT_SUBJECT CONTENT_LENGTH CONTENT_TYPE GATEWAY_INTERFACE HTTPS HTTPS_KEYSIZE HTTPS_SECRETKEYSIZE HTTPS_SERVER_ISSUER HTTPS_SERVER_SUBJECT INSTANCE_ID INSTANCE_META_PATH LOCAL_ADDR LOGON_USER PATH_INFO PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST REMOTE_USER REQUEST_METHOD SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PORT_SECURE SERVER_PROTOCOL SERVER_SOFTWARE URL HTTP_CACHE_CONTROL HTTP_CONNECTION HTTP_ACCEPT HTTP_ACCEPT_ENCODING HT...

MSSQL - How to set Case Sensitive in varchar data type

The default setting of the varchar data type in MSSQL2008 is non-case sensitive. The lower-case is equal the upper-case ex. cat = CaT. If you need the difference between upper-case and lower-case on your data, you can set your field by: 1. Right click on your table and select "Design". 2. Click on your field you need to set " Case-Sensitive " and see at "Column Properties" window below. 3. In "Column Properties" window, find "Table Designer" and click on the right column of "collation" 4. In the pop up window. Choose "windows Collation" -> Dictionary Sort and check on Case Sensitive 5. Click "OK" to finish.

C# - DateTime To String

String _display = DateTime.Now.ToString("dd/MM/yyyy"); _display result is: 27/12/2011 You can display by .NET Datetime format characters as the following: d - Numeric day of the month without a leading zero. dd - Numeric day of the month with a leading zero. ddd - Abbreviated name of the day of the week. dddd - Full name of the day of the week. f,ff,fff,ffff,fffff,ffffff - Fraction of a second. The more Fs the higher the precision. h - 12 Hour clock, no leading zero. hh - 12 Hour clock with leading zero. H - 24 Hour clock, no leading zero. HH - 24 Hour clock with leading zero. m - Minutes with no leading zero. mm - Minutes with leading zero. M - Numeric month with no leading zero ex.2. MM - Numeric month with a leading zero ex.02. MMM - Abbreviated name of month ex.Dec MMMM - Full month name ex.December. s - Seconds with no leading zero. ss - Seconds with leading zero. t - AM/PM but only the first letter. tt - AM/PM ( a.m. / p.m...

MSSQL - Set permission to update database MSSQL2008

In MSSQL2008 Server, when you change/edit table schema, sometimes you can not save change. The error you found is " Saving change is not permitted . The changes you have made require the following tables to be dropped and re-created....." You can fixed this problem with this solution. Solution: - In SQL Server Management Studio > Go to Tools Menu > Options > Designers - Find the option "Prevent saving changes that require a table re-creation" and unchecked it. Now, you can save changed your new schema.

C# - Convert Image URL To BASE64

public String ConvertImageURLToBase64(String url) {      StringBuilder _sb = new StringBuilder();      Byte[] _byte = this.GetImage(url);      _sb.Append(Convert.ToBase64String(_byte, 0, _byte.Length));      return _sb.ToString(); } private byte[] GetImage(string url) {      Stream stream = null;      byte[] buf;      try      {           WebProxy myProxy = new WebProxy();           HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);           HttpWebResponse response = (HttpWebResponse)req.GetResponse();           stream = response.GetResponseStream();  ...