标题: 技术小笔记 [打印本页] 作者: 王新阳 时间: 2012-11-16 18:49 标题: 技术小笔记 《无限级分类》
private void Bindtree(TreeNode treenode, string pid) 代表接受在页面加载传过来的TreeNode
{ pid代表要查询的字段
DataTable dt = Pro_showManager.selectTreeview(pid);
foreach (DataRow rs in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = rs["Name"].ToString();
tn.Value = rs["id"].ToString();
if (pid == "0")
{
TreeView1.Nodes.Add(tn);
}
else
{
treenode.ChildNodes.Add(tn);
}
Bindtree(tn, rs["id"].ToString());
}
} 《在sql里有冗余信息只留一条剩余删除》
select * from Score where ScoreId not in (select max(ScoreId) from dbo.Score group by [Name], Score, GroupId, IP)
delete Score where ScoreId not in (select max(ScoreId) from dbo.Score group by [Name], Score, GroupId, IP) 《插入一条语句返回本次插入的id》 insert into 表名(字段名) values(值。。。。)
select SCOPE_IDENTITY(); --返回本次语句块中插入数据的最后一个自增量ID
insert into 表名(字段名) values(值。。。。)
select @@IDENTITY; --返回整个数据库中插入数据的最后一个自增量ID 《触发器》
-------关键代码------
CREATE TRIGGER trig_delete_transInfo
ON transInfo
FOR DELETE
AS
print '开始备份数据,请稍后......'
IF NOT EXISTS(SELECT * FROM sysobjects
WHERE name='backupTable')
SELECT * INTO backupTable FROM deleted
ELSE
INSERT INTO backupTable SELECT * FROM deleted
print '备份数据成功,备份表中的数据为:'
SELECT * FROM backupTable
GO
《ROW_NUMBER() over(order by id)分页存储过程》 create proc p_存储过程名
@当前页 int,@每页显示多少条 int
as
select * from (select *,ROW_NUMBER() over(order by id) as 排序 drom (表名)) a
where 排序 between (@当前页-1)*@每页显示多少条+1 and @当前页*@每页显示多少条
go 《上传图片》 if (FileUpload1.HasFile)//判断FileUpload1是否为空(返回类型bool)
{
string s = Server.MapPath(".");//得到根目录
string s3 = this.FileUpload1.FileName;//得到添加的文件名
string s2 = s + "/images/" + s3;
this.FileUpload1.SaveAs(s2);//将文件存在服务器
}
《做批量删除的时候拼接字符串》 create proc p_daleteuserinfo //存储过程名
@username nvarchar(1000)
as
if @username<>'' //判断是否为空以防报错
begin
declare @sql varchar(500) //定义字符串变量
set @sql= 'delete from UserInfo where '@username //把传过来的字符串和变量拼起来
exec(@sql) ////最后执行变量