C#邦定下拉框
//下拉框ID ddlDept
//-----------------------
//-----------------------
Code
public class PubConstant
{
/// <summary>
/// 获取连接字符串
/// </summary>
public static string ConnectionString
{
get
{
string _connectionString = ConfigurationManager.ConnectionStrings["dbConStr"].ConnectionString;
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
_connectionString = DESEncrypt.Decrypt(_connectionString);
}
return _connectionString;
}
}
//
//--------------------------------------
public abstract class DbHelperSQL
{
//数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库.
public static string connectionString = PubConstant.ConnectionString;
//------------------------
//web.config
<add name="dbConStr" connectionString="packet size= 4096; min pool size = 0; max pool size= 1000; pooling = true; server=.;database=aaa;uid=sa;pwd=bbb" providerName="System.Data.SqlClient"/>
//-----------------------------
public static DataSet RunProcedure(string storedProcName, string tableName, int Times)
{
/*
CommandTimeout 属性可设置或返回执行命令期间在终止尝试和产生错误之前需等待的时间。
设置或返回 Long 值,该值指示等待命令执行的秒数。默认值为 30。
*/
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
SqlCommand command = new SqlCommand(storedProcName, connection);
command.CommandType = CommandType.StoredProcedure;
sqlDA.SelectCommand = command;
sqlDA.SelectCommand.CommandTimeout = Times;
sqlDA.Fill(dataSet, tableName);
connection.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return dataSet;
}
}
//----------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
DataSet _ds = new DataSet();
ConduitPercentDAL _ConduitPercentDAL =new ConduitPercentDAL();
_ds = _ConduitPercentDAL.DeptDS();
ddlDept.DataSource = _ds;
ddlDept.DataTextField = "configDeptName";
ddlDept.DataValueField = "configDeptName";
ddlDept.DataBind();
}
//--------完--------------
public class PubConstant
{
/// <summary>
/// 获取连接字符串
/// </summary>
public static string ConnectionString
{
get
{
string _connectionString = ConfigurationManager.ConnectionStrings["dbConStr"].ConnectionString;
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
_connectionString = DESEncrypt.Decrypt(_connectionString);
}
return _connectionString;
}
}
//
//--------------------------------------
public abstract class DbHelperSQL
{
//数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库.
public static string connectionString = PubConstant.ConnectionString;
//------------------------
//web.config
<add name="dbConStr" connectionString="packet size= 4096; min pool size = 0; max pool size= 1000; pooling = true; server=.;database=aaa;uid=sa;pwd=bbb" providerName="System.Data.SqlClient"/>
//-----------------------------
public static DataSet RunProcedure(string storedProcName, string tableName, int Times)
{
/*
CommandTimeout 属性可设置或返回执行命令期间在终止尝试和产生错误之前需等待的时间。
设置或返回 Long 值,该值指示等待命令执行的秒数。默认值为 30。
*/
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
SqlCommand command = new SqlCommand(storedProcName, connection);
command.CommandType = CommandType.StoredProcedure;
sqlDA.SelectCommand = command;
sqlDA.SelectCommand.CommandTimeout = Times;
sqlDA.Fill(dataSet, tableName);
connection.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return dataSet;
}
}
//----------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
DataSet _ds = new DataSet();
ConduitPercentDAL _ConduitPercentDAL =new ConduitPercentDAL();
_ds = _ConduitPercentDAL.DeptDS();
ddlDept.DataSource = _ds;
ddlDept.DataTextField = "configDeptName";
ddlDept.DataValueField = "configDeptName";
ddlDept.DataBind();
}
//--------完--------------