复制代码 代码如下:
private static SqlConnection Sqlconnection;
public static SqlConnection SqlConnection
{
get
{
string SqlconnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TandyTang"].ToString();
if (Sqlconnection == null)
{
Sqlconnection = new SqlConnection(SqlconnectionString);
Sqlconnection.Open();
}
else if (Sqlconnection.State == System.Data.ConnectionState.Closed)
{
Sqlconnection.Open();
}
else if (Sqlconnection.State == System.Data.ConnectionState.Broken)
{
Sqlconnection.Close();
Sqlconnection.Open();
}
return Sqlconnection;
}
}
///<summary>
/// SqlGetDataTable
///<param></param>
///<param></param>
///<param></param>
///<param></param>
///<returns>DataTable</returns>
public static DataTable SqlGetDataTable(string proc, CommandType type, string[] param, out int count)
{
DataSet ds = new DataSet();
using (SqlCommand cmd = new SqlCommand(proc, SqlConnection))
{
SqlParameter[] myParms = new SqlParameter[2];
myParms[0] = new SqlParameter("@Id", SqlDbType.Int, 4);
myParms[0].Value = paramValue[0];
myParms[1] = new SqlParameter("@Name", SqlDbType.VarChar, 50);
myParms[1].Value = paramValue[1];
foreach (SqlParameter parameter in myParms)
{
cmd.Parameters.Add(parameter);
}
cmd.CommandType = type;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
return ds.Tables[0];
}
复制代码 代码如下:
private static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TandyTang"].ConnectionString;
///<summary>
/// SqlGetDataTable
///<param></param>
///<param></param>
///<param></param>
///<param></param>
///<returns>DataTable</returns>
public static DataTable SqlGetDataTable(string proc, CommandType type, string[] param, out int count)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(proc, con))
{
SqlParameter[] myParms = new SqlParameter[11];
myParms[0] = new SqlParameter("@Id", SqlDbType.Int, 4);
myParms[0].Value = paramValue[0];
myParms[1] = new SqlParameter("@Name", SqlDbType.VarChar, 50);
myParms[1].Value = paramValue[1];
foreach (SqlParameter parameter in myParms)
{
cmd.Parameters.Add(parameter);
}
cmd.CommandType = type;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
}
return ds.Tables[0];
}
}
新闻热点
疑难解答
图片精选