Posts

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();  ...

MSSQL - how to change "SA" password

1. Open the "SQL Server Enterprise Manager". This is usually under "Start"-->"Programs"-->"Microsoft SQL Server". 2. Navigate to the "Logins" object under the "Security" folder on the SQL Server you wish to administer. Then, right click on the 'sa' account and select "Properties". 3. Now, enter a new password in the "Password" field under the "Authentication" options. website reference: http://www.eukhost.com/forums/f31/how-change-mssql-sa-password-511

MSSQL - select a random row

Microsoft SQL Server provide function "NEWID()" to random record from database. Let's see example. SELECT TOP 1 column FROM table ORDER BY NEWID() Example: SELECT TOP 1 code_item FROM game_item WHERE available=1 ORDER BY NEWID()