网站越来越慢,大家帮我看看数据库访问的代码有问题么?
我是C#初学者。任何方面的问题都有可能。
namespace SimCity.Data
{
using System;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// SqlHelper 的摘要说明。
/// </summary>
public class SqlHelper
{
public SqlHelper()
{
}
public static void ExecuteStoreProcedure(string strConnection, string strStoredProcedure, SqlParameter []arParas, out int nReturnValue)
{
SqlConnection connection = new SqlConnection(strConnection);
connection.Open();
SqlCommand command = new SqlCommand(strStoredProcedure, connection);
if(arParas != null && arParas.Length > 0)
{
foreach(SqlParameter para in arParas)
{
command.Parameters.Add(para);
}
}
SqlParameter parRet = command.Parameters.Add( "@returnvalue ",SqlDbType.NVarChar,30);
parRet.Direction = ParameterDirection.ReturnValue;
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
nReturnValue = (int)parRet.Value;
}
public static void ExecuteStoreProcedure(string strConnection, string strStoredProcedure, SqlParameter []arParas)
{
SqlConnection connection = new SqlConnection(strConnection);
connection.Open();
SqlCommand command = new SqlCommand(strStoredProcedure, connection);
if(arParas != null && arParas.Length > 0)
{
foreach(SqlParameter para in arParas)
{
command.Parameters.Add(para);
}
}
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
}
public static DataSet FillDataSet(string strConnection, string strStoredProcedure, SqlParameter []arParas, string strTableName)
{
DataSet dataset = null;
SqlConnection connection = new SqlConnection(strConnection);
dataset = new DataSet();
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand(strStoredProcedure, connection);
if(arParas != null && arParas.Length > 0)
{
foreach(SqlParameter para in arParas)
{
command.Parameters.Add(para);
}
}
command.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand = command;
adapter.Fill(dataset, strTableName);
command.Dispose();
adapter.Dispose();
connection.Close();
return dataset;
}
public static DataSet FillDataSet(string strConnection, string strStoredProcedure, SqlParameter []arParas, out int nReturnValue)