就是判断有没有我所要查询的数据(给出的条件是 模糊查询也就是like),由于数据量比较大,用like查询速度太慢了,想请问下各位高手有没有可以优化的地方,只要能实现我的要求,任何方法都可以
解决方案 »
- 如何使用这段代码?
- 诡异的正则
- 数据库里如果只有2条数据,我要查询5条出来,没有就有空表示,急
- 如何通过一个函数输出两个数组?
- 朋友们,帮我解决一个特郁闷的问题2003打sp1不定后,外网不能访问web站点
- 为什么,调试时,我的页面上看不到控件。(C#2003,asp.net)来者有分
- 为什么使用用另一个项目中的对象及方法时,没有动态提示?
- 为什么ds里的数据总是清了掉呢,帮我看看吧,谢谢
- 如何连接ACESS和ORACLE?
- sqlcommand对象的Parameters集合有什么用?谁有关于它的简单的实例?
- C#, .NET, 面试总结,以及WPF的经典电子书
- ★★★【分享C#源代码(数据工具和C#游戏程序)】★★★
这样索引会失效
所以建议在Like 时 只是用后%
首先下载AjaxPro.dll到Bin目录添加Lookup.js//// JScript File
var DIV_BG_COLOR = "#FFE0C0";
var DIV_HIGHLIGHT_COLOR = "#6699FF";
var DIV_FONT = "Arial";
var DIV_PADDING = "2px";
var DIV_BORDER = "1px solid #CCC";
var queryField;
var divName;
var ifName;
var lastVal = "";
var val = "";
var globalDiv;
var divFormatted = false;function InitQueryCode( queryFieldName, hiddenDivName )
{
queryField = document.getElementById( queryFieldName );
queryField.onblur = hideDiv;
queryField.onkeydown = keypressHandler;
queryField.autocomplete = "off";
if( hiddenDivName )
{
divName = hiddenDivName;
}
else
{
divName = "querydiv";
}
ifName = "queryiframe";
setTimeout("mainLoop()",100);
}function getDiv(divID)
{
if(!globalDiv)
{
if(!document.getElementById(divID))
{
var newNode = document.createElement("div");
newNode.setAttribute("id", divID);
document.body.appendChild(newNode);
}
globalDiv = document.getElementById(divID);
var x = queryField.offsetLeft;
var y = queryField.offsetTop + queryField.offsetHeight;
var parent = queryField;
while(parent.offsetParent)
{
parent = parent.offsetParent;
x += parent.offsetLeft;
y += parent.offsetTop;
}
if(!divFormatted)
{
globalDiv.style.backgroundColor = DIV_BG_COLOR;
globalDiv.style.fontFamily = DIV_FONT;
globalDiv.style.padding = DIV_PADDING;
globalDiv.style.border = DIV_BORDER;
globalDiv.style.width = "100px";
globalDiv.style.fontSize = "90%";
globalDiv.style.position = "absolute";
globalDiv.style.left = x + "px";
globalDiv.style.top = y + "px";
globalDiv.style.visibility = "hidden";
globalDiv.style.zIndex = 10000;
divFormatted = true;
}
}
return globalDiv;
}function showQueryDiv(resultArray)
{
var div = getDiv(divName);
while( div.childNodes.length > 0 )
{
div.removeChild(div.childNodes[0]);
}
for(var i = 0; i < resultArray.length; i++)
{
var result = document.createElement("div");
result.style.cursor = "pointer";
result.style.padding = "2px 0px 2px 0px";
result.style.width = div.style.width;//Add width
_unhighlightResult(result);
result.onmousedown = selectResult;
result.onmouseover = highlightResult;
result.onmouseout = unhighlightResult;
var value = document.createElement("span");
value.className = "value";
value.style.textAlign = "left";
value.style.fontWeight = "bold";
value.innerHTML = resultArray[i];
result.appendChild(value);
div.appendChild(result);
}
showDiv(resultArray.length > 0);
}function selectResult()
{
_selectResult(this);
}
function _selectResult( item )
{
var spans = item.getElementsByTagName("span");
if( spans )
{
for(var i = 0; i < spans.length; i++)
{
if( spans[i].className == "value" )
{
queryField.value = spans[i].innerHTML;
lastVar = val = escape( queryField.value );
mainLoop();
queryField.focus();
showDiv( false );
return;
}
}
}
}function highlightResult()
{
_highlightResult( this );
}function _highlightResult( item )
{
item.style.backgroundColor = DIV_HIGHLIGHT_COLOR;
}function unhighlightResult()
{
_unhighlightResult( this );
}function _unhighlightResult( item )
{
item.style.backgroundColor = DIV_BG_COLOR;
}function showDiv( show )
{
var div = getDiv( divName );
if( show )
{
div.style.visibility = "visible";
}
else
{
div.style.visibility = "hidden";
}
adjustiFrame();
}function hideDiv()
{
showDiv( false );
}function keypressHandler(evt)
{
var div = getDiv( divName );
if( div.style.visibility == "hidden" )
{
return true;
}
if( !evt && window.event )
{
evt = window.event;
}
var key = evt.keyCode;
var KEYUP = 38;
var KEYDOWN = 40;
var KEYENTER = 13;
var KEYTAB = 9;
if(( key != KEYUP ) && ( key != KEYDOWN ) && ( key != KEYENTER ) && ( key != KEYTAB ))
{
return true;
}
var selNum = getSelectedSpanNum( div );
var selSpan = setSelectedSpan( div, selNum );
if( key == KEYENTER || key == KEYTAB )
{
if( selSpan )
{
_selectResult(selSpan);
}
evt.cancelBubble= true;
return false;
}
else
{
if( key == KEYUP)
{
selSpan = setSelectedSpan( div, selNum - 1 );
}
if( key == KEYDOWN )
{
selSpan = setSelectedSpan( div, selNum + 1 );
}
if( selSpan )
{
_highlightResult( selSpan );
}
}
showDiv( true );
return true;
}function getSelectedSpanNum( div )
{
var count = -1;
var spans = div.getElementsByTagName("div");
if( spans )
{
for( var i = 0; i < spans.length; i++)
{
count++;
if( spans[i].style.backgroundColor != div.style.backgroundColor )
{
return count;
}
}
}
return -1;
}
function setSelectedSpan( div, spanNum )
{
var count = -1;
var thisDiv;
var divs = div.getElementsByTagName("div");
if( divs )
{
for( var i = 0; i < divs.length; i++ )
{
if( ++count == spanNum )
{
_highlightResult( divs[i] );
thisDiv = divs[i];
}
else
{
_unhighlightResult( divs[i] );
}
}
}
return thisDiv;
}function adjustiFrame()
{
if(!document.getElementById(ifName))
{
var newNode = document.createElement("iFrame");
newNode.setAttribute("id", ifName);
newNode.setAttribute("src","javascript:false;");
newNode.setAttribute("scrolling","no");
newNode.setAttribute("frameborder","0");
document.body.appendChild( newNode );
}
iFrameDiv = document.getElementById( ifName );
var div = getDiv( divName );
try
{
iFrameDiv.style.position = "absolute";
iFrameDiv.style.width = div.offsetWidth;
iFrameDiv.style.height = div.offsetHeight;
iFrameDiv.style.top = div.style.top;
iFrameDiv.style.left = div.style.left;
iFrameDiv.style.zIndex = div.style.zIndex - 1;
iFrameDiv.style.visibility = div.style.visibility;
}
catch (e)
{}
}
<head runat="server">
<title>AjaxPro.NET AutoQueryTextBox</title>
<script language="javascript" src="lookup.js"></script>
<script language="jscript">
mainLoop = function()
{
val = escape( queryField.value );
if( lastVal != val )
{
var response = _Default.GetSearchItems( val );
showQueryDiv( response.value );
lastVal = val;
}
setTimeout('mainLoop()', 100);
return true;
}
</script>
</head>
<body >
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BackColor="#C0C0FF" Font-Bold="True" Font-Overline="False"
Font-Size="XX-Large" Height="37px" Width="475px">
51aspx.com AutoQueryTextBox</asp:Panel>
<br />
<hr align="left" style="width: 473px" />
<br />
输入查询字串: <asp:TextBox ID="txSearch" runat="server"
Width="134px"></asp:TextBox> <br />
<br />
</div>
<script language="jscript">
InitQueryCode("" + '<%= txSearch.ClientID %>' + "");
</script>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using AjaxPro;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default));
} [AjaxMethod()]// or [AjaxPro.AjaxMethod]
public ArrayList GetSearchItems( string strQuery )
{
//生成数据源
ArrayList items = new ArrayList();
items.Add("51aspx");
items.Add("aspx");
items.Add("asp.net");
items.Add("51aspx.com");
items.Add("51aspx51aspx");
items.Add("www.51aspx.com");
items.Add("aspx.net"); //筛选数据
ArrayList selectItems = new ArrayList();
foreach( string str in items )
{
if (str.ToUpper().IndexOf(strQuery.ToUpper()) == 0)
{
selectItems.Add(str);
}
}
return selectItems;
}
}
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
不过还是非常感谢。。
你去www.Google.cn去体验一下.你并没有搜索,,但是已经在下拉列表里面看到你能搜索到的值了.
2、不要在程序脚本中直接写查询语句,把查询做成存储过程,这样可以提高速度。
3、Sybase在处理查询时需要占用tempdb空间,检查一下tempdb的大小,必要的话扩大tempdb。
4、如果所查询的表中数据太多,建议先取出一些可能的数据,然后建立一个临时表,查询工作可在这个临时表中进行。
所以建议在Like 时 只是用后%
---------------
已经说的很明白了~
pxh360395296
拼C搏#
等 级:
发表于:2008-01-07 15:53:054楼 得分:0
除了存储过程,我再也想不出什么办法了
Tulipfly
等 级:
发表于:2008-01-07 16:00:215楼 得分:0
是全模糊查询,觉得用like,如果数据量很大的话,查询速度会相当的慢
这样速度会快些
---->where 字段 like '+@sd+%'