您的位置:首页 > 其它

个人的web开发心得(三)----------非常适合入门新手,都是常识

2006-09-13 13:41 573 查看
21.在释放所有资源时,调用该方法,

public void Dispose()
{
//GC.SuppressFinalize(this); //这句的 作用是 告诉GC不要调用this的终结器
}

22.检查连接是否在打开状态

if(conn.State.ToString().ToUpper() != "Open".ToUpper())conn.Open() ;



if(conn.State = ConnectionState.Closed )conn.Open() ;



if(conn.state!= ConnectionState.Open)conn.Open();

23.Microsoft Data Access Application Block

24.在js中 调用服务器的代码
方法1:

if(confirm(".......")
{
<%
你的服务器代码
%>
}
else
{
<%
你的服务器代码
%>
}

方法2:
if(confirm("...."))
{button1.click();}
else
{button2.click();}

将两个按钮 高度和宽度都设为 0 (不能设button.visible=false)
方法3:
if(confirm("...."))
{ document.all.textbox1.value="1";} //一定要注意在js中是这种形式。 或者用<%调用 服务器的代码%>不过我没试过
else
{ document.all.textbox1.value="2";
document.location.href="treeview.aspx"; //转向别的页面
}

代码再根据 textbox1.text值 进行判断 并分别执行不同的代码。

25.获得系统时间

string sYear = Convert.ToString(System.DateTime.Now.Year);
string sMonth = Convert.ToString(System.DateTime.Now.AddMonths(1).Month);

26.如何将A表的数据更新到B表?

只要求更新部分字段数据,该如何实现?

方法1:update b set col=a.col from a where a.id=b.id

方法2:update b set b.col=a.col from a,b where a.id=b.id

方法3:update b
set col=a.col
from b
inner join a
on a.id=b.id

方法4:update b set b.col=a.col
from b
Left Join a
on b.id = a.id

27删除数据库中的表,并创建一个新的
drop table Year_KPIValue
create table Year_KPIValue
(
ID int Identity PRIMARY KEY,//序号,主键,自动累加
Dept varchar(20),//部门
KPIName varchar(50),//KPI名称
Time datetime,//评价时间
KPIValue varchar(20),//KPI分值
DeptValuer varchar(20),//评价部门名称
);

28.

/// <summary>
/// 正则表达式验证是否是数字
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
static bool IsNumeric(string str)
{
System.Text.RegularExpressions.Regex reg1
= new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
return reg1.IsMatch(str);
}

29.
判断 DataGrid 内容为空时也显示表头内容.

if (ds.Tables(0).Rows.Count == 0) {
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow());
gridView.DataSource = ds;
gridView.DataBind();
int columnCount = gridView.Rows(0).Cells.Count;
gridView.Rows(0).Cells.Clear();
gridView.Rows(0).Cells.Add(new TableCell());
gridView.Rows(0).Cells(0).ColumnSpan = columnCount;
gridView.Rows(0).Cells(0).Text = "No Records Found.";
}

GridView记录为空时 显示表头记录

#region 如果内容为空 则显示表头
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columnCount = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columnCount;
//GridView1.Rows[0].Cells[0].Text = "No Records Found.";
}
else
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
#endregion

30. 查询 name不为空 的记录
SELECT * FROM TABLE WHERE (name is not null)
select * from table where (len(name)>1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐