62,046
社区成员
发帖
与我相关
我的任务
分享
SqlCommand cmd = new SqlCommand();
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = procedureName;
for (int i = 0; i < sqlParameters.Length; i++)
{
//dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
cmd.Parameters.Add(sqlParameters[i]);
}
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
就最后一句慢。剩下其他的代码都不慢的。
下面是拼接参数的代码
pagecount = 0;
itemcount = 0;
SqlParameter[] thisParms = new SqlParameter[9];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@tbname", SqlDbType.NVarChar,1000);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[0].Value = tbname;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@fieldkey", SqlDbType.NVarChar,1000);
thisParms[1].Direction = ParameterDirection.Input;
thisParms[1].Value = fieldkey;
thisParms[2] = new System.Data.SqlClient.SqlParameter("@where", SqlDbType.NVarChar,4000);
thisParms[2].Direction = ParameterDirection.Input;
thisParms[2].Value = where;
thisParms[3] = new System.Data.SqlClient.SqlParameter("@fieldshow", SqlDbType.NVarChar,2000);
thisParms[3].Direction = ParameterDirection.Input;
thisParms[3].Value = fieldshow;
thisParms[4] = new System.Data.SqlClient.SqlParameter("@fieldorder", SqlDbType.NVarChar, 2000);
thisParms[4].Direction = ParameterDirection.Input;
thisParms[4].Value = fieldorder;
thisParms[5] = new System.Data.SqlClient.SqlParameter("@pagecurrent", SqlDbType.Int);
thisParms[5].Direction = ParameterDirection.Input;
thisParms[5].Value = pagecurrent;
thisParms[6] = new System.Data.SqlClient.SqlParameter("@pagesize", SqlDbType.Int);
thisParms[6].Direction = ParameterDirection.Input;
thisParms[6].Value = pagesize;
thisParms[7] = new System.Data.SqlClient.SqlParameter("@pagecount", SqlDbType.Int, 32);
thisParms[7].Direction = ParameterDirection.Output;
thisParms[8] = new System.Data.SqlClient.SqlParameter("@itemcount", SqlDbType.Int, 32);
thisParms[8].Direction = ParameterDirection.Output;
string ErrorMessage = "";
DataSet ds = new DataSet();
if (SQLCommon.ExecuteStoredProcedure("xt_Common_PagingLarge", conn, ref thisParms, out ds, out ErrorMessage))
{
pagecount = Convert.ToInt32(thisParms[7].Value.ToString());
itemcount = Convert.ToInt32(thisParms[8].Value.ToString());
return ds;
}
throw new Exception(ErrorMessage);