.net 关于数据库数据检索速度疑问?
SQL检索代码如下:
select ta.*,tb.BillNo as BillNoCX from (select GoodID,ScanCode as ScanCodID,GoodName,Spec,Unit,FactCode as FactCodID,RetailPric,MemPric,WholeSalePric,STBYPricA,STBYPricB,STBYPricC,STBYPricD,STBYPricE,LogPacks,goodtypeid as GoodType,SpeOffFlag,CXRange,MemberBeginLevel,MemberEndLevel,CXPric,CXKL,GoodPrtyID from jcv_goodbaseinfo where (ScanCode='0101010641' or goodid='0101010641' or goodname like '%0101010641%')) ta left join jcpscxinfo tb on ta.goodid=tb.goodid
在SQL查询分析器里执行耗时:0.1秒
在.NET中利用数据库操作类检索耗时在2~3秒,请问什么原因,我的.NET代码如下:
DateTime dt1 = System.DateTime.Now;
DataTable dtReturn;
string strSearchVar = textBox1.Text.Trim();
string strSql = "select ta.*,tb.BillNo as BillNoCX from (select GoodID,ScanCode as ScanCodID,GoodName,Spec,Unit,FactCode as FactCodID,RetailPric,MemPric,WholeSalePric,STBYPricA,STBYPricB,STBYPricC,STBYPricD,STBYPricE,LogPacks,goodtypeid as GoodType,SpeOffFlag,CXRange,MemberBeginLevel,MemberEndLevel,CXPric,CXKL,GoodPrtyID from jcv_goodbaseinfo where (ScanCode='" + strSearchVar + "' or goodid='" + strSearchVar + "' or goodname like '%" + strSearchVar + "%')) ta left join jcpscxinfo tb on ta.goodid=tb.goodid ";
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandText = strSql;
if (sqlConnection.State != ConnectionState.Open)
{
sqlConnection.Open();
}
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = sqlCommand;
DataSet dataSet = new DataSet();
SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
sqlDataAdapter.Fill(dataSet);
dtReturn = dataSet.Tables[0];
double k = (DateTime.Now - dt1).TotalSeconds; //计算耗时
sqlCommand.Dispose();
sqlDataAdapter.Dispose();
//sqlConnection.Close();