2014年1月26日 星期日

[.NET] 取得Server或Client IP

1. 取得Server IP語法:
using System.Net;
IPAddress ServerIP = IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);
Response.Write("Server IP=" + ServerIP.ToString());

2. 取得Client IP
string strClientIP = Request.ServerVariables["REMOTE_ADDR"].ToString();
string strClientIP = Request.UserHostAddress;
//使用代理伺服器
string strClientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();



參考資料:
http://blog.xuite.net/sunnysoap/r/25283108-C%23+%E5%A6%82%E4%BD%95%E5%8F%96%E5%BE%97%E6%9C%AC%E6%A9%9F(Server)%E7%9A%84IP
http://www.dotblogs.com.tw/jimmyyu/archive/2009/05/21/8493.aspx


http://bytes.com/topic/asp-net/answers/848515-how-get-client-ip-address-assigned-isp
http://dotnetstock.com/technical/how-to-get-ip-address-of-a-client-system-using-asp-net
http://csharpdotnetfreak.blogspot.com/2008/12/finding-ip-address-behind-proxy-using-c.html
http://forums.asp.net/t/1780050.aspx

[C#] 這個資料列已經屬於其他資料表

說明:
從DataTable依條件篩選出一些DataRow,想匯入另一DataTable object,卻出現Exception:這個資料列已經屬於其他資料表,例:
DataTable dtTemp = dtSource.Clone();
dtTemp.Rows.add(dr);

解決方法:
使用DataTable的ImportRow方法,例:
DataTable dtTemp = dtSource.Clone();
dtTemp.ImportRow(dr);


參考資料:
http://blog.mu1979.idv.tw/2007/10/datatabledatarowdatatable.html

[Cystal Report] DateAdd與DateDiff函式使用記錄

語法:
DateDiff (intervalType, startDateTime, endDateTime)
DateAdd (intervalType, nIntervals, startDateTime)
Year (CurrentDate) //取得Date之西元年

例:
DateDiff ("m", CDate (Mid({?Cycle}, 1, 10)), DateAdd ("d", 1, CDate (Mid({?Cycle}, 12, 10))))


參考資料:
http://pic.dhe.ibm.com/infocenter/rsawshlp/v7r5m0/index.jsp?topic=%2Fcom.businessobjects.integration.eclipse.designer.doc%2Fhtml%2Ftopic682.html


2014年1月20日 星期一

[T-SQL] REPLICATE與{fn LENGTH(string)}函數使用記錄

說明:依照table某欄位字串長度,加上某長度的特定字元。


作法:
1. 使用ODBC純量函數中的LENGTH函數。
    語法:SELECT {fn <function_name> [ (<argument>,.... n) ] }
    例: SELECT {fn LENGTH(Function_ID)}

2. 使用REPLICATE函數。
    語法:REPLICATE ( string_expression ,integer_expression )
    例:REPLICATE('=', {fn LENGTH(Function_ID)}-1)


參考資料:
http://msdn.microsoft.com/zh-tw/library/ms174383.aspx
http://jengting.blogspot.tw/2011/08/sql.html
http://www.dotblogs.com.tw/atowngit/archive/2010/10/04/18077.aspx
http://technet.microsoft.com/zh-tw/library/bb630290.aspx
http://msdn.microsoft.com/zh-tw/library/ms710249.aspx




2014年1月1日 星期三

[ASP.NET] 網頁導向Response.Redirect與Server.Transfer

說明:網頁導向有Response.Redirect與Server.Transfer兩種方法,有什麼不同?


說明:
Response.Redirect不會保留表單值,可導向外部網站,但送出兩次Request,一次給Source.aspx,一次給Destination.aspx。可用在get傳值。
例:
Response.Redirect("Destination.aspx?Value="+strValue);

Server.Transfer恰好相反,可保留表單值,但只限同一網站,Request一次效能較佳。


參考資料:
http://www.dotblogs.com.tw/jimmyyu/archive/2009/11/10/11503.aspx