Thursday, July 28, 2005

don't forget ( and ) in sql query if using both AND & OR

//--------------- correct query
strSQL = "select download_agent from afc.agent where download_agent=agent_nbr and Agent_type='D' and download_agent = '"& sessiondata("strAgencyCode") &"' and (COMM_PRODUCTS = 'V' or COMM_PRODUCTS = 'A') with ur"

//incorrect query
strSQL = "select download_agent from afc.agent where download_agent=agent_nbr and Agent_type='D' and download_agent = '"& sessiondata("strAgencyCode") &"' and COMM_PRODUCTS = 'V' or COMM_PRODUCTS = 'A' with ur"

Wednesday, July 20, 2005

access datasource in Itembound (datagrid/repeater)

in the OnItemDataBound event handler, sometimes you want to access the datasource of a control. whether the datasource is a object, or just a field of a dataset, you can always access it using following code:

DataRowView drv = (DataRowView)e.Item.DataItem;
//then access the specific field
string str = drv["fieldname"].ToString();

time to use Server.UrlEncode()

if passing some special characters in the query string, like # & <>, it will cause broswer to mis-interpretate them, so when constructing query string, you should use Server.UrlEncode()

example:

string qs = "formname="+ Server.UrlEncode(drv[from].tostring());