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.Data.SqlClient;
/// <summary>
/// SqlConnections 的摘要说明
/// </summary>
namespace System.mySQLConnection
{
public class SqlConnections
{
//当前连接的是第几个。
static int count = 0;
//最大连接量
static int maxCount = 30;
static SqlConnection[] sqlConns = new SqlConnection[maxCount];
//自己创建自己
static SqlConnections myConn = new SqlConnections();
//初始化
private SqlConnections()
{
for (int i = 0; i < maxCount; i++)
{
sqlConns[i] = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ADOStr"].ToString());
}
}
//根据条件来获取不同的表,与字段。
public static DataTable GetDataTable(String sqlTest, String tableName)
{
try
{
DataSet myDS = new DataSet();
SqlDataAdapter myAdapater = new SqlDataAdapter(sqlTest, SqlConnections.GetSQLConnection());
myAdapater.Fill(myDS, tableName);
return myDS.Tables[tableName];
}
catch (SqlException sqlE)
{
return null;
}
}
// 获取数据库连接
public static SqlConnection GetSQLConnection()
{
try
{
try
{
sqlConns[count].Close();
}
catch (Exception eeX)
{
}
return sqlConns[count];
}
finally
{
//当前个数自加。。
if (count == (maxCount - 1))
{
count = 0;
}
else
{
count++;
}
}
}
//返回一个参数
public static String GetNumOneField(String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlConnTemp.Open();
return sqlCommT.ExecuteScalar().ToString();
}
catch (Exception sqlE)
{
return "没有";
}
finally
{
sqlConnTemp.Close();
}
}
//返回一个参数
public static String GetNumOneField(SqlConnection sqlConnTemp,SqlTransaction tempSqlTran ,String sqlTxt)
{
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = tempSqlTran;
return sqlCommT.ExecuteScalar().ToString();
}
catch (Exception sqlE)
{
return "没有";
}
finally
{
//sqlConnTemp.Close();
}
}
/// <summary>
/// 做 ,修改,删除,
/// </summary>
/// <param name="sqlTxt">执行的SQL语句</param>
/// <returns>返回的结果影响多少行</returns>
public static int UpdateOrDelete(String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
public static int UpdateOrDelete(CommandType _CommandType, SqlParameter[] _sqlParas, String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.CommandType = _CommandType;
sqlCommT.Parameters.Clear();
for (int a = 0; a < _sqlParas.Length; a++)
{
sqlCommT.Parameters.Add(_sqlParas[a]);
}
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
/// <summary>
/// 带事务的增,删,改数据执行方法(警告:该方法必须 手动开关数据,而且还有手动的提交事务。否则不能更新数据)
/// </summary>
/// <param name="_SqlConn">数据库连接对象</param>
/// <param name="_SqlTran">事务对象</param>
/// <param name="sqlTxt">执行的Sql语句</param>
/// <returns></returns>
public static int UpdateOrDelete(SqlConnection _SqlConn,SqlTransaction _SqlTran, String sqlTxt)
{
SqlConnection sqlConnTemp = _SqlConn;
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = _SqlTran;
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
public static int UpdateOrDelete(SqlConnection _SqlConn, SqlTransaction _SqlTran, CommandType _CommandType, SqlParameter [] _sqlParas, String sqlTxt)
{
SqlConnection sqlConnTemp = _SqlConn;
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = _SqlTran;
sqlCommT.CommandType = _CommandType;
sqlCommT.Parameters.Clear();
for (int a = 0; a < _sqlParas.Length; a++)
{
sqlCommT.Parameters.Add(_sqlParas[a]);
}
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
// sqlConnTemp.Close();
}
}
/// <summary>
/// 有存储过的查询
/// </summary>
/// <param name="StoredProcedureName">存储过程的名字</param>
/// <param name="sqlParas">所有参数</param>
/// <param name="tableName">表名</param>
/// <returns>DataTable的结果集</returns>
public static DataTable GetDataTable(String StoredProcedureName, SqlParameter [] sqlParas,String tableName)
{
try
{
DataSet myDS = new DataSet();
SqlDataAdapter myAdapater = new SqlDataAdapter(StoredProcedureName, SqlConnections.GetSQLConnection());
myAdapater.SelectCommand.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < sqlParas.Length; i++)
{
//if (myAdapater.SelectCommand.Parameters.Contains(sqlParas[i]))
//myAdapater.SelectCommand.Parameters.RemoveAt(sqlParas[i].ParameterName);
myAdapater.SelectCommand.Parameters.Add(sqlParas[i]);
}
myAdapater.Fill(myDS, tableName);
myAdapater.SelectCommand.Parameters.Clear();
myAdapater.Dispose();
return myDS.Tables[tableName];
}
catch (SqlException sqlE)
{
return null;
}
}
}
}
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.Data.SqlClient;
/// <summary>
/// SqlConnections 的摘要说明
/// </summary>
namespace System.mySQLConnection
{
public class SqlConnections
{
//当前连接的是第几个。
static int count = 0;
//最大连接量
static int maxCount = 30;
static SqlConnection[] sqlConns = new SqlConnection[maxCount];
//自己创建自己
static SqlConnections myConn = new SqlConnections();
//初始化
private SqlConnections()
{
for (int i = 0; i < maxCount; i++)
{
sqlConns[i] = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ADOStr"].ToString());
}
}
//根据条件来获取不同的表,与字段。
public static DataTable GetDataTable(String sqlTest, String tableName)
{
try
{
DataSet myDS = new DataSet();
SqlDataAdapter myAdapater = new SqlDataAdapter(sqlTest, SqlConnections.GetSQLConnection());
myAdapater.Fill(myDS, tableName);
return myDS.Tables[tableName];
}
catch (SqlException sqlE)
{
return null;
}
}
// 获取数据库连接
public static SqlConnection GetSQLConnection()
{
try
{
try
{
sqlConns[count].Close();
}
catch (Exception eeX)
{
}
return sqlConns[count];
}
finally
{
//当前个数自加。。
if (count == (maxCount - 1))
{
count = 0;
}
else
{
count++;
}
}
}
//返回一个参数
public static String GetNumOneField(String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlConnTemp.Open();
return sqlCommT.ExecuteScalar().ToString();
}
catch (Exception sqlE)
{
return "没有";
}
finally
{
sqlConnTemp.Close();
}
}
//返回一个参数
public static String GetNumOneField(SqlConnection sqlConnTemp,SqlTransaction tempSqlTran ,String sqlTxt)
{
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = tempSqlTran;
return sqlCommT.ExecuteScalar().ToString();
}
catch (Exception sqlE)
{
return "没有";
}
finally
{
//sqlConnTemp.Close();
}
}
/// <summary>
/// 做 ,修改,删除,
/// </summary>
/// <param name="sqlTxt">执行的SQL语句</param>
/// <returns>返回的结果影响多少行</returns>
public static int UpdateOrDelete(String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
public static int UpdateOrDelete(CommandType _CommandType, SqlParameter[] _sqlParas, String sqlTxt)
{
SqlConnection sqlConnTemp = SqlConnections.GetSQLConnection();
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.CommandType = _CommandType;
sqlCommT.Parameters.Clear();
for (int a = 0; a < _sqlParas.Length; a++)
{
sqlCommT.Parameters.Add(_sqlParas[a]);
}
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
/// <summary>
/// 带事务的增,删,改数据执行方法(警告:该方法必须 手动开关数据,而且还有手动的提交事务。否则不能更新数据)
/// </summary>
/// <param name="_SqlConn">数据库连接对象</param>
/// <param name="_SqlTran">事务对象</param>
/// <param name="sqlTxt">执行的Sql语句</param>
/// <returns></returns>
public static int UpdateOrDelete(SqlConnection _SqlConn,SqlTransaction _SqlTran, String sqlTxt)
{
SqlConnection sqlConnTemp = _SqlConn;
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = _SqlTran;
sqlConnTemp.Open();
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
//sqlConnTemp.Close();
}
}
public static int UpdateOrDelete(SqlConnection _SqlConn, SqlTransaction _SqlTran, CommandType _CommandType, SqlParameter [] _sqlParas, String sqlTxt)
{
SqlConnection sqlConnTemp = _SqlConn;
try
{
SqlCommand sqlCommT = new SqlCommand(sqlTxt, sqlConnTemp);
sqlCommT.Transaction = _SqlTran;
sqlCommT.CommandType = _CommandType;
sqlCommT.Parameters.Clear();
for (int a = 0; a < _sqlParas.Length; a++)
{
sqlCommT.Parameters.Add(_sqlParas[a]);
}
return sqlCommT.ExecuteNonQuery();
}
catch (SqlException sqlE)
{
return 0;
}
finally
{
// sqlConnTemp.Close();
}
}
/// <summary>
/// 有存储过的查询
/// </summary>
/// <param name="StoredProcedureName">存储过程的名字</param>
/// <param name="sqlParas">所有参数</param>
/// <param name="tableName">表名</param>
/// <returns>DataTable的结果集</returns>
public static DataTable GetDataTable(String StoredProcedureName, SqlParameter [] sqlParas,String tableName)
{
try
{
DataSet myDS = new DataSet();
SqlDataAdapter myAdapater = new SqlDataAdapter(StoredProcedureName, SqlConnections.GetSQLConnection());
myAdapater.SelectCommand.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < sqlParas.Length; i++)
{
//if (myAdapater.SelectCommand.Parameters.Contains(sqlParas[i]))
//myAdapater.SelectCommand.Parameters.RemoveAt(sqlParas[i].ParameterName);
myAdapater.SelectCommand.Parameters.Add(sqlParas[i]);
}
myAdapater.Fill(myDS, tableName);
myAdapater.SelectCommand.Parameters.Clear();
myAdapater.Dispose();
return myDS.Tables[tableName];
}
catch (SqlException sqlE)
{
return null;
}
}
}
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net 数据库的连接和datatable类”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。