取时间段 8:00到8:00
select * from lir_data where time_now in
(select time_now from lir_data where convert(char(8), time_now ,108)>='08:00:00' and
convert(char(10), time_now ,20)=convert(char(10), getdate()-1 ,20))
union
select * from lir_data where time_now in
(select time_now from lir_data where convert(char(8), time_now ,108)<='08:00:00'
and convert(char(10), time_now ,20)=convert(char(10), getdate() ,20))
...//定在8点运行
select sum(yl) from data where datediff(hh,time_now,getdate()-1)>=-16 and datediff(hh,time_now,getdate()-1)<=8 and convert(char(10), time_now ,20)>=convert(char(10),getdate()-1,20)
删除表内重复内容
delete from infotable where id not in(select min(id) from infotable group by title) and datediff(d,releasetime,getdate())=0
delete from dove_info where id not in(select min(id) from dove_info group by filename)
//iframe的高度随内容自动增大水晶报表注册码
注册号:6707437608
密码:AAP5GKS0000GDE100DS
function autoResize(strObj)
{
try {
//var Obj;
//Obj=strObj.replace(/'/g,'');
document.all[strObj].style.height=web1.document.body.scrollHeight;
}
catch(e){}
}
<IFRAME frameBorder=0 id=web4 name=web scrolling=no src="chat2/chat_main.asp" style="height:expression(1); aho:expression(autoResize('web1')); width:100%;"></IFRAME>
---------------------------动态页面变为xmlhttp---------
<script language="javascript">
function re()
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET","http://www.sina.com.cn/",false);
http.send();
var str = http.responseText;
document.write(str);
//alert(str);
//t.innerHTML=str;
}
re();
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<span id=t></span>
--------- 选择图片<select> 随change改变 --------
<script language="javascript">
function change()
{
document.forms[0].pic.src = "images/" +document.forms[0].select1[document.forms[0].select1.selectedIndex].value+".gif";
}
</script>
<table width="100%" border="0" cellspacing="0">
<tr>
<td width="130" align="center"><select onChange="change()" name="select1">
<option value="head_001" selected>001</option>
<option value="head_005">005</option>
<option value="head_006">006</option>
</select>
<span class="style15">*</span> <span class="style6">请选择图片</span>
</td>
<td><img name="pic" id="pic" src="images/head_001.gif" width="100" height="100">
</td>
</tr>
</table>
后台获得的值代码
string img_name = this.Request.Form["select1"].ToString();
----------- 读取文件和写文件 --------
System.Text.Encoding.UTF8.ToString();
Session["adid"]=1;
string to_pagou1=ConfigurationSettings.AppSettings["to_pagou"].ToString();
string ad_file = "";
string ad_file1="";
string search_width1="";
string flxx_ad_file1="";
string flxx_ad_file2="";
string textbox_adfile1="";
string textbox_adfile2="";
ad_file1="ad_model/ad001.js";
StreamReader fileStream = new StreamReader(Server.MapPath(ad_file1.ToString()),System.Text.Encoding.Default);
ad_file1="";
ad_file = fileStream.ReadToEnd();
if(flxx.Checked==false&&textbox.Checked==true)
{
flxx_ad_file1=ad_file.Substring(0,ad_file.IndexOf("//&"));
flxx_ad_file2=ad_file.Substring(ad_file.LastIndexOf("//&"));
ad_file=flxx_ad_file1.ToString()+flxx_ad_file2.ToString();
}
if(textbox.Checked==false&&flxx.Checked==true)
{
textbox_adfile1=ad_file.Substring(0,ad_file.IndexOf("//*"));
textbox_adfile2=ad_file.Substring(ad_file.LastIndexOf("//*"));
ad_file=textbox_adfile1.ToString()+textbox_adfile2.ToString();
}
if(textbox.Checked==false&&flxx.Checked==false)
{
flxx_ad_file1=ad_file.Substring(0,ad_file.IndexOf("//&"));
textbox_adfile2=ad_file.Substring(ad_file.LastIndexOf("//*"));
ad_file=flxx_ad_file1.ToString()+textbox_adfile2.ToString();
}
if(search_width.Text=="")
{
search_width.Text="700";
search_width1=search_width.Text.ToString();
}
else {
search_width1=search_width.Text.Trim().ToString();
}
ad_file=ad_file.Replace("¤width¤",search_width1);
ad_file = ad_file.Replace("¤url¤",to_pagou1);
ad_file = ad_file.Replace("¤adid¤",Session["adid"].ToString());
ad_file = ad_file.ToString();
string adid=Session["adid"].ToString();
fileStream.Close();
StreamWriter Writefile = new StreamWriter(Server.MapPath("ad/"+adid.ToString()+".js"),false,System.Text.Encoding.Default);
//Writefile = System.IO.File.CreateText(Server.MapPath("ad/"+adid.ToString()+".js"));
Writefile.Write(ad_file.ToString());
Writefile.Close();
string str = "";
str = "<script language=javascript src=";
str = str + to_pagou1.ToString()+"ad/"+adid.ToString()+".js";
str = str + "></script>";
code.Visible = true;
code.Text = str.ToString();
----弹出对话框-------
String scriptString = "<script language=javascript>";
scriptString += "alert('非常感谢您对爬狗网的大力支持,我们将及时认真地处理您所提出的问题,请留意主页左侧“网友提问与解答”栏目!');";
//scriptString += "window.open('index.aspx') ";
scriptString += "</script>";
if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
==============XmlHttp ===========
function loadFragmentInToElement(fragment_url, element_id)
{
var element = document.getElementById(element_id);
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("GET", fragment_url);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
element.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
函数的调用方法如下所示:
loadFragmentInToElement( 'http://domain.com/url.php' , DynamicContent_id );
有了上边的代码,再配合JavaScript 的定时函数,我们就可以实现定时的无刷新数据更新了,下边这个函数每隔
5 秒对element_id 的数据进行一次更新。
function refresh( element_id )
{
loadFragmentInToElement( 'show.php' , '' + element_id );
setTimeout( "refresh('ts')" , 5000 );
}
------------- div的应用 根据select 的值 来显示多少个select ---------
<script language="javascript">
function change()
{
var sum = document.Form1.num.selectedIndex;
var str = "";
var i;
for(i=1;i<=sum;i++)
{
str = str + "<select name=select"+i+">";
str = str + "<option selected>请选择</option>";
str = str + "<option Value=百姓话题>百姓话题 </option>";
str = str + "<option Value=业内交流>业内交流</option>";
str = str + "<option Value=土地信息>土地信息</option>";
str = str + "<option Value=地产人才>地产人才</option>";
str = str + "<option Value=企业服务>企业服务</option>";
str = str + "<option Value=搜索引擎及分类信息>搜索引擎及分类信息</option>";
str = str + "<option Value=娱乐新闻>娱乐新闻</option>";
str = str + "<option Value=贴图专区>贴图专区</option>";
str = str + "<option Value=搞笑世界>搞笑世界</option>";
str = str + "</select>";
str = str + "<br>";
}
div1.innerHTML=str;
}
</script>
<form id=Form1 method=post>
<tr>
<td style="HEIGHT: 14px">请选择:
<select onchange="change()" name="num">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select> <font color="red">*</font>你可以同时选择在6个板块发布你的主题 1 是默认本板块</td>
</tr>
<tr><td><div id=div1></div></td></tr></form>
后台获值 this.Request.Form["select4"].ToString()=="企业服务";
this.DropDownList1.SelectedValue.ToString()=="地产人才"
---------------- 解决asp.net传值 到asp显示乱码的问题---------
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
---------------------- 验证控件------------
"^\\d+$" //非负整数(正整数 + 0)
"^[0-9]*[1-9][0-9]*$" //正整数
"^((-\\d+)|(0+))$" //非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$" //负整数
"^-?\\d+$" //整数
"^\\d+(\\.\\d+)?$" //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$" //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
"^(-?\\d+)(\\.\\d+)?$" //浮点数
------------------- 鼠标移动 到DataGrid 的某一行是改变颜色 -------------------
后台代码
private viod changeRowColor(object sender ,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
}}
}
-------- 在datagrid 前添加序号 ---------
<asp:TemplateColumn>
<ItemTemplate>
<%#(DataGrid1.CurrentPageIndex*DataGrid1.PageSize+DataGrid1.Items.Count+1)%>
</ItemTemplate>
</asp:TemplateColumn>
------------ 判断字符串是否是数字的函数--------
private bool IsNum(String str)
{
for(int i=0;i<str.Length;i++)
{
if(str[i]>47&&str[i]<58)
{
return true;
}
}
return false;
}
----------------------- (SQL Server 存储过程的分页 ---------------
建立表:
CREATE TABLE [TestTable] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Note] [nvarchar] (2000) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
插入数据:(2万条,用更多的数据测试会明显一些)
SET IDENTITY_INSERT TestTable ON
declare @i int
set @i=1
while @i<=20000
begin
insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, ''FirstName_XXX'',''LastName_XXX'',''Country_XXX'',''Note_XXX'')
set @i=@i+1
end
SET IDENTITY_INSERT TestTable OFF
-------------------------------------
分页方案一:(利用Not In和SELECT TOP分页)
语句形式:
SELECT TOP 10 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP 20 id
FROM TestTable
ORDER BY id))
ORDER BY ID
SELECT TOP 页大小 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP 页大小*页数 id
FROM 表
ORDER BY id))
ORDER BY ID
-------------------------------------
分页方案二:(利用ID大于多少和SELECT TOP分页)
语句形式:
SELECT TOP 10 *
FROM TestTable
WHERE (ID >
(SELECT MAX(id)
FROM (SELECT TOP 20 id
FROM TestTable
ORDER BY id) AS T))
ORDER BY ID
SELECT TOP 页大小 *
FROM TestTable
WHERE (ID >
(SELECT MAX(id)
FROM (SELECT TOP 页大小*页数 id
FROM 表
ORDER BY id) AS T))
ORDER BY ID
-------------------------------------
分页方案三:(利用SQL的游标存储过程分页)
create procedure XiaoZhengGe
@sqlstr nvarchar(4000), --查询字符串
@currentpage int, --第N页
@pagesize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 总页数--,@rowcount as 总行数,@currentpage as 当前页
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
其它的方案:如果没有主键,可以用临时表,也可以用方案三做,但是效率会低。
建议优化的时候,加上主键和索引,查询效率会提高。
通过SQL 查询分析器,显示比较:我的结论是:
分页方案二:(利用ID大于多少和SELECT TOP分页)效率最高,需要拼接SQL语句
分页方案一:(利用Not In和SELECT TOP分页) 效率次之,需要拼接SQL语句
分页方案三:(利用SQL的游标存储过程分页) 效率最差,但是最为通用
------------------- 一段能有效禁止刷新网页、禁止"后退"(或网页立即过期)的代码 -----
<body onload="if(history.length>0){window.opener=null;window.close();window.open(window.location.href,'_blank');}">
----- 把DataGrid1的一列的和显示在页脚 -------
private int sum=0;
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemIndex>=0)
{
sum+=int.Parse(e.Item.Cells[3].Text);
}
else if(e.Item.ItemType==ListItemType.Footer)
{
e.Item.Cells[0].Text="总和为:";
e.Item.Cells[1].Text=sum.ToString();
e.Item.Cells[2].Text="平均值为";
e.Item.Cells[3].Text=((int)(sum/DataGrid1.Items.Count)).ToString();
}
}