.net 学习笔记(1)
1.某文件是否存在:
string photopath = HttpContext.Current.Server.MapPath(path.ToString());
if (System.IO.File.Exists(photopath))
{return path.ToString();
else
{return System.Web.Configuration.WebConfigurationManager.AppSettings["webpath"].ToString() + "images/default.gif";}
2.数据缓存的简单使用:
public DataTable BindCountry2(string Key)
{
string key = Key;
if (HttpContext.Current.Cache[key] == null)
{
string sql = "GetCountry";
DataTable dt = SqlHelper.ExecuteDataset(GetCon.ConnString, CommandType.StoredProcedure, sql).Tables[0];
HttpContext.Current.Cache.Add(key, dt, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(30), CacheItemPriority.Normal, null);
}
return (DataTable)HttpContext.Current.Cache[key];
}
3.Cache 移除缓存项时通知应用程序的回调方法。
public delegate void CacheItemRemovedCallback (
string key,
Object value,
CacheItemRemovedReason reason
)
参数
key
从缓存中移除的键。
value
与从缓存中移除的键关联的 Object 项。
reason
CacheItemRemovedReason 枚举指定的、从缓存移除项的原因。
4.1 使用FREETEXT对数据库进行任意文本查询
FREETEXT接受两个参数。第一个参数表示要检索的列(或*,表示检索所有的列),第二个参数表示要检索的短语。
如:select CompanyName from companyinfo where freetext(CompanyName,'Thai')
4.2 使用freetexttable对数据库进行任意文本查询
freetexttable返回一个匹配结果的表(带2个列:KEY(关键字),RANK(排名0~1000))。
一盘使用联合查询,如:select RANK, CompanyName from companyinfo, freetexttable(companyinfo,CompanyName,'Thai Trade Point.com Co.,Ltd.') searchtable where [KEY]=companyinfo.ID order by RANK desc
4.3 使用CONTAINS对数据库数据进行布尔(Boolean)查询
注意:如果在任意文本查询中使用布尔运算符,那么该操作就会被完全忽略。
使用CONTAINS谓词,如:select CompanyName from companyinfo where contains(CompanyName,'Thai and not trade' ),其中的and与not为布尔运算。
使用CONTAINSTABLE,其函数返回一个包含两个列的表:KEY(关键字)和RANK(排名)。
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai and trade') searchtable where [KEY]=companyinfo.ID order by RANK desc
可以使用前缀术语,必须用引号吧检索关键字括起来并且使用*作为通配符。
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai and "*t*"') searchtable where [KEY]=companyinfo.ID order by RANK desc
可以牌匹配变长的单词。使用formsof操作符
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'formsof(inflectional,td)') searchtable where [KEY]=companyinfo.ID order by RANK desc
使用临近操作
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai near co') searchtable where [KEY]=companyinfo.ID order by RANK desc
5 缓存依赖
...
string photopath = HttpContext.Current.Server.MapPath(path.ToString());
if (System.IO.File.Exists(photopath))
{return path.ToString();
else
{return System.Web.Configuration.WebConfigurationManager.AppSettings["webpath"].ToString() + "images/default.gif";}
2.数据缓存的简单使用:
public DataTable BindCountry2(string Key)
{
string key = Key;
if (HttpContext.Current.Cache[key] == null)
{
string sql = "GetCountry";
DataTable dt = SqlHelper.ExecuteDataset(GetCon.ConnString, CommandType.StoredProcedure, sql).Tables[0];
HttpContext.Current.Cache.Add(key, dt, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(30), CacheItemPriority.Normal, null);
}
return (DataTable)HttpContext.Current.Cache[key];
}
3.Cache 移除缓存项时通知应用程序的回调方法。
public delegate void CacheItemRemovedCallback (
string key,
Object value,
CacheItemRemovedReason reason
)
参数
key
从缓存中移除的键。
value
与从缓存中移除的键关联的 Object 项。
reason
CacheItemRemovedReason 枚举指定的、从缓存移除项的原因。
4.1 使用FREETEXT对数据库进行任意文本查询
FREETEXT接受两个参数。第一个参数表示要检索的列(或*,表示检索所有的列),第二个参数表示要检索的短语。
如:select CompanyName from companyinfo where freetext(CompanyName,'Thai')
4.2 使用freetexttable对数据库进行任意文本查询
freetexttable返回一个匹配结果的表(带2个列:KEY(关键字),RANK(排名0~1000))。
一盘使用联合查询,如:select RANK, CompanyName from companyinfo, freetexttable(companyinfo,CompanyName,'Thai Trade Point.com Co.,Ltd.') searchtable where [KEY]=companyinfo.ID order by RANK desc
4.3 使用CONTAINS对数据库数据进行布尔(Boolean)查询
注意:如果在任意文本查询中使用布尔运算符,那么该操作就会被完全忽略。
使用CONTAINS谓词,如:select CompanyName from companyinfo where contains(CompanyName,'Thai and not trade' ),其中的and与not为布尔运算。
使用CONTAINSTABLE,其函数返回一个包含两个列的表:KEY(关键字)和RANK(排名)。
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai and trade') searchtable where [KEY]=companyinfo.ID order by RANK desc
可以使用前缀术语,必须用引号吧检索关键字括起来并且使用*作为通配符。
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai and "*t*"') searchtable where [KEY]=companyinfo.ID order by RANK desc
可以牌匹配变长的单词。使用formsof操作符
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'formsof(inflectional,td)') searchtable where [KEY]=companyinfo.ID order by RANK desc
使用临近操作
如:select RANK, CompanyName from companyinfo, containstable(companyinfo,CompanyName,'Thai near co') searchtable where [KEY]=companyinfo.ID order by RANK desc
5 缓存依赖
...

浙公网安备 33010602011771号