《ASP.NET1200例》当前上下文中不存在名称configurationmanager

时间:2021-10-26 03:56:34

当前上下文中不存在名称ConfigurationManager的解决方法

今晚做项目在DBHelper.cs类中的数据库连接要改到web.config里面调用,结果在编译的时候却发现提示错误:

当前上下文中不存在名称"ConfigurationManager"

明明是已经添加了using System.Configuration但还是不行,后来回想了一下,还要再添加什么的,怪我不认真,真是的,原来还要在DAL类库中添加引用,加入里面的System.Configuration

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Configuration; namespace DBUtility
{
public abstract class DbHelperSQL
{
/// <summary>
/// 数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库.
/// </summary>
public static string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; /// <summary>
/// 创建 SqlCommand 对象实例(用来返回一个整数值)
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <returns>SqlCommand 对象实例</returns>
private static SqlCommand BuildIntCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);
command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, , ParameterDirection.ReturnValue, false, , , string.Empty, DataRowVersion.Default, null));
return command;
} /// <summary>
/// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值)
/// </summary>
/// <param name="connection">数据库连接</param>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <returns>SqlCommand</returns>
private static SqlCommand BuildQueryCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = new SqlCommand(storedProcName, connection)
{
CommandType = CommandType.StoredProcedure
};
foreach (SqlParameter parameter in parameters)
{
if (parameter != null)
{
if (((parameter.Direction == ParameterDirection.InputOutput) || (parameter.Direction == ParameterDirection.Input)) && (parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
command.Parameters.Add(parameter);
}
}
return command;
} /// <summary>
/// 判断是否存在某表的某个字段
/// </summary>
/// <param name="tableName">表名称</param>
/// <param name="columnName">列名称</param>
/// <returns>是否存在</returns>
public static bool ColumnExists(string tableName, string columnName)
{
object single = GetSingle("select count(1) from syscolumns where [id]=object_id('" + tableName + "') and [name]='" + columnName + "'");
if (single == null)
{
return false;
}
return (Convert.ToInt32(single) > );
} /// <summary>
/// 执行查询语句,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
/// </summary>
/// <param name="strSQL">查询语句</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(string strSQL)
{
SqlDataReader reader2;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(strSQL, connection);
try
{
connection.Open();
reader2 = command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException exception)
{
throw exception;
}
return reader2;
} /// <summary>
/// 执行查询语句,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
/// </summary>
/// <param name="strSQL">查询语句</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(string SQLString, params SqlParameter[] cmdParms)
{
SqlDataReader reader2;
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, conn, null, SQLString, cmdParms);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
reader2 = reader;
}
catch (SqlException exception)
{
throw exception;
}
return reader2;
} /// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString)
{
int num2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
num2 = command.ExecuteNonQuery();
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return num2;
} /// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString, params SqlParameter[] cmdParms)
{
int num2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int num = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
num2 = num;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
}
}
return num2;
} /// <summary>
/// 执行SQL语句,返回影响的记录数,不会自动关闭连接
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <param name="_connection">connection</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString, SqlConnection _connection)
{
int num2;
SqlCommand command = new SqlCommand(SQLString, _connection);
try
{
_connection.Open();
num2 = command.ExecuteNonQuery();
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
return num2;
} /// <summary>
/// 执行带一个存储过程参数的的SQL语句。
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString, string content)
{
int num2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
SqlParameter parameter = new SqlParameter("@content", SqlDbType.NText)
{
Value = content
};
command.Parameters.Add(parameter);
try
{
connection.Open();
num2 = command.ExecuteNonQuery();
}
catch (SqlException exception)
{
throw exception;
}
finally
{
command.Dispose();
connection.Close();
}
}
return num2;
} /// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString, SqlConnection conn, params SqlParameter[] cmdParms)
{
int num2;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, conn, null, SQLString, cmdParms);
int num = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
num2 = num;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
}
return num2;
} /// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString, string _connectionString, params SqlParameter[] cmdParms)
{
int num2;
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int num = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
num2 = num;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
}
}
return num2;
} public static int ExecuteSqlByTime(string SQLString, int Times)
{
int num2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
command.CommandTimeout = Times;
num2 = command.ExecuteNonQuery();
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return num2;
} /// <summary>
/// 执行带一个存储过程参数的的SQL语句。
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
/// <returns>影响的记录数</returns>
public static object ExecuteSqlGet(string SQLString, string content)
{
object obj3;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
SqlParameter parameter = new SqlParameter("@content", SqlDbType.NText)
{
Value = content
};
command.Parameters.Add(parameter);
try
{
connection.Open();
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
command.Dispose();
connection.Close();
}
}
return obj3;
} /// <summary>
/// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例)
/// </summary>
/// <param name="strSQL">SQL语句</param>
/// <param name="fs">图像字节,数据库的字段类型为image的情况</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSqlInsertImg(string strSQL, byte[] fs)
{
int num2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(strSQL, connection);
SqlParameter parameter = new SqlParameter("@fs", SqlDbType.Image)
{
Value = fs
};
command.Parameters.Add(parameter);
try
{
connection.Open();
num2 = command.ExecuteNonQuery();
}
catch (SqlException exception)
{
throw exception;
}
finally
{
command.Dispose();
connection.Close();
}
}
return num2;
} /// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">多条SQL语句</param>
public static int ExecuteSqlTran(List<string> SQLStringList)
{
int num3;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = new SqlCommand
{
Connection = connection
};
SqlTransaction transaction = connection.BeginTransaction();
command.Transaction = transaction;
try
{
int num = ;
for (int i = ; i < SQLStringList.Count; i++)
{
string str = SQLStringList[i];
if (str.Trim().Length > )
{
command.CommandText = str;
num += command.ExecuteNonQuery();
}
}
transaction.Commit();
num3 = num;
}
catch
{
transaction.Rollback();
num3 = ;
}
}
return num3;
} /// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">SQL语句的哈希表(key为sql语句,value是该语句的SqlParameter[])</param>
public static void ExecuteSqlTran(Hashtable SQLStringList)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
{
SqlCommand cmd = new SqlCommand();
try
{
foreach (DictionaryEntry entry in SQLStringList)
{
string cmdText = entry.Key.ToString();
SqlParameter[] cmdParms = (SqlParameter[])entry.Value;
PrepareCommand(cmd, connection, transaction, cmdText, cmdParms);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
}
} /// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">SQL语句的哈希表(key为sql语句,value是该语句的SqlParameter[])</param>
public static void ExecuteSqlTranWithIndentity(Hashtable SQLStringList)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
{
SqlCommand cmd = new SqlCommand();
try
{
int num = ;
foreach (DictionaryEntry entry in SQLStringList)
{
string cmdText = entry.Key.ToString();
SqlParameter[] cmdParms = (SqlParameter[])entry.Value;
foreach (SqlParameter parameter in cmdParms)
{
if (parameter.Direction == ParameterDirection.InputOutput)
{
parameter.Value = num;
}
}
PrepareCommand(cmd, connection, transaction, cmdText, cmdParms);
cmd.ExecuteNonQuery();
foreach (SqlParameter parameter2 in cmdParms)
{
if (parameter2.Direction == ParameterDirection.Output)
{
num = Convert.ToInt32(parameter2.Value);
}
}
cmd.Parameters.Clear();
}
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
}
} public static bool Exists(string strSql)
{
int num;
object single = GetSingle(strSql);
if (object.Equals(single, null) || object.Equals(single, DBNull.Value))
{
num = ;
}
else
{
num = int.Parse(single.ToString());
}
if (num == )
{
return false;
}
return true;
} public static bool Exists(string strSql, params SqlParameter[] cmdParms)
{
int num;
object single = GetSingle(strSql, cmdParms);
if (object.Equals(single, null) || object.Equals(single, DBNull.Value))
{
num = ;
}
else
{
num = int.Parse(single.ToString());
}
if (num == )
{
return false;
}
return true;
} /// <summary>
/// 得到指定列的最大值
/// </summary>
/// <param name="FieldName">列名</param>
/// <param name="TableName">表名</param>
/// <returns>最大值</returns>
public static int GetMaxID(string FieldName, string TableName)
{
return GetMaxID(FieldName, TableName, "");
} /// <summary>
/// 得到指定条件、指定列的最大值
/// </summary>
/// <param name="FieldName">列名</param>
/// <param name="TableName">表名</param>
/// <param name="strWhere">条件</param>
/// <returns></returns>
public static int GetMaxID(string FieldName, string TableName, string strWhere)
{
string sQLString = "select max(" + FieldName + ")+1 from " + TableName;
if (!string.IsNullOrEmpty(strWhere))
{
sQLString = sQLString + " Where " + strWhere;
}
object single = GetSingle(sQLString);
if (single == null)
{
return ;
}
return int.Parse(single.ToString());
} /// <summary>
/// 得到指定条件、指定列的最大值
/// </summary>
/// <param name="FieldName">列名</param>
/// <param name="TableName">表名</param>
/// <param name="strWhere">条件</param>
/// <returns></returns>
public static long GetMaxIDLong(string FieldName, string TableName, string strWhere)
{
string sQLString = "select max(" + FieldName + ")+1 from " + TableName;
if (!string.IsNullOrEmpty(strWhere))
{
sQLString = sQLString + " Where " + strWhere;
}
object single = GetSingle(sQLString);
if (single == null)
{
return 1L;
}
return long.Parse(single.ToString());
} /// <summary>
/// 执行一条计算查询结果语句,返回查询结果(object)。
/// </summary>
/// <param name="SQLString">计算查询结果语句</param>
/// <returns>查询结果(object)</returns>
public static object GetSingle(string SQLString)
{
object obj3;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return obj3;
} /// <summary>
/// 执行一条计算查询结果语句,返回查询结果(object)。
/// </summary>
/// <param name="SQLString">计算查询结果语句</param>
/// <returns>查询结果(object)</returns>
public static object GetSingle(string SQLString, params SqlParameter[] cmdParms)
{
object obj3;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
object objA = cmd.ExecuteScalar();
cmd.Parameters.Clear();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
}
}
return obj3;
} public static object GetSingle(string SQLString, int Times)
{
object obj3;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
command.CommandTimeout = Times;
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return obj3;
} public static object GetSingle(string SQLString, string _connectionString)
{
object obj3;
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return obj3;
} public static object GetSingle(string SQLString, string _connectionString, int Times)
{
object obj3;
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand(SQLString, connection);
try
{
connection.Open();
command.CommandTimeout = Times;
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return obj3;
} public static object GetSingle(string SQLString, string _connectionString, params SqlParameter[] cmdParms)
{
object obj3;
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
object objA = cmd.ExecuteScalar();
cmd.Parameters.Clear();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
obj3 = objA;
}
catch (SqlException exception)
{
throw exception;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
}
}
return obj3;
} private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
{
cmd.Transaction = trans;
}
cmd.CommandType = CommandType.Text;
if (cmdParms != null)
{
foreach (SqlParameter parameter in cmdParms)
{
if (((parameter.Direction == ParameterDirection.InputOutput) || (parameter.Direction == ParameterDirection.Input)) && (parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
cmd.Parameters.Add(parameter);
}
}
} /// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
new SqlDataAdapter(SQLString, connection).Fill(dataSet, "ds");
}
catch (SqlException exception)
{
throw new Exception(exception.Message);
}
return dataSet;
}
} /// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString, params SqlParameter[] cmdParms)
{
DataSet set2;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataSet dataSet = new DataSet();
try
{
adapter.Fill(dataSet, "ds");
cmd.Parameters.Clear();
}
catch (SqlException exception)
{
throw new Exception(exception.Message);
}
set2 = dataSet;
}
}
return set2;
} public static DataSet Query(string SQLString, int Times)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
new SqlDataAdapter(SQLString, connection) { SelectCommand = { CommandTimeout = Times } }.Fill(dataSet, "ds");
}
catch (SqlException exception)
{
throw new Exception(exception.Message);
}
return dataSet;
}
} public static DataSet Query(string SQLString, string _connectionString)
{
using (SqlConnection connection = new SqlConnection(_connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
new SqlDataAdapter(SQLString, connection).Fill(dataSet, "ds");
}
catch (SqlException exception)
{
throw new Exception(exception.Message);
}
return dataSet;
}
} /// <summary>
/// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);
command.CommandType = CommandType.StoredProcedure;
return command.ExecuteReader(CommandBehavior.CloseConnection);
} /// <summary>
/// 执行存储过程
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name="tableName">DataSet结果中的表名</param>
/// <returns>DataSet</returns>
public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
connection.Open();
new SqlDataAdapter { SelectCommand = BuildQueryCommand(connection, storedProcName, parameters) }.Fill(dataSet, tableName);
connection.Close();
return dataSet;
}
} /// <summary>
/// 执行存储过程,返回影响的行数
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name="rowsAffected">影响的行数</param>
/// <returns></returns>
public static int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
return (int)command.Parameters["ReturnValue"].Value;
}
} public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName, int Times)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet dataSet = new DataSet();
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter
{
SelectCommand = BuildQueryCommand(connection, storedProcName, parameters)
};
adapter.SelectCommand.CommandTimeout = Times;
adapter.Fill(dataSet, tableName);
connection.Close();
return dataSet;
}
} /// <summary>
/// Runs the procedure.
/// </summary>
/// <param name="storedProcName">Name of the stored proc.</param>
/// <param name="parameters">The parameters.</param>
/// <param name="tableName">Name of the table.</param>
/// <param name="connstr">The connstr.</param>
/// <returns></returns>
public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName, string connstr)
{
using (SqlConnection connection = new SqlConnection(connstr))
{
DataSet dataSet = new DataSet();
connection.Open();
new SqlDataAdapter { SelectCommand = BuildQueryCommand(connection, storedProcName, parameters) }.Fill(dataSet, tableName);
connection.Close();
return dataSet;
}
} /// <summary>
/// 表是否存在
/// </summary>
/// <param name="TableName"></param>
/// <returns></returns>
public static bool TabExists(string TableName)
{
int num;
object single = GetSingle("select count(*) from sysobjects where id = object_id(N'[" + TableName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1");
if (object.Equals(single, null) || object.Equals(single, DBNull.Value))
{
num = ;
}
else
{
num = int.Parse(single.ToString());
}
if (num == )
{
return false;
}
return true;
} }
}

《ASP.NET1200例》当前上下文中不存在名称configurationmanager的更多相关文章

  1. Visual Studio 当前上下文中不存在名称&OpenCurlyDoubleQuote;ConfigurationManager”

    Visual Studio调试出现错误:当前上下文中不存在名称“ConfigurationManager” 解决方法: 1.System.Configuration引用这个dll参考:http://k ...

  2. C&num;中提示:当前上下文中不存在名称&OpenCurlyDoubleQuote;ConfigurationManager”

    场景 想要在程序中获取App.config中设置的内容. 想要通过 ConfigurationManager.AppSettings[key]; 来进行获取,已经添加 using System.Con ...

  3. asp&period;net webform 当前上下文中不存在名称&OpenCurlyDoubleQuote;&lowbar;&lowbar;o”

    错误 CS0103 当前上下文中不存在名称“__o” 最近在搞一个webform项目, 再页面写了点<%%>代码, 结果编译下居然出现了这个错误 炸裂啊,  这是什么毛线, 看起来是 In ...

  4. 《ASP&period;NET1200例》实现投票的用户控件

    用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...

  5. 《ASP&period;NET1200例》高亮显示ListView中的数据行并自动切换图片

    aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...

  6. 《ASP&period;NET1200例》ListView控件之修改,删除与添加

    aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...

  7. 《ASP&period;NET1200例》ListView 控件与DataPager控件的结合&lt&semi;二&gt&semi;

    ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...

  8. 《ASP&period;NET1200例》解决母版页报错&OpenCurlyDoubleQuote;内容控件必须是内容页中的*控件,或是引用母版页的嵌套母版页。”

    VS2005下,添加了母版页这个控件,我们可以讲N个页面*同的部分放在母版页来实现,并让WEB窗体集成自我们的母版页,就可以让我们的站点具有统一的风格了.在VS2005SP1之前的版本中,我们只能创 ...

  9. 《ASP&period;NET1200例》ListView 控件与DataPager控件的结合&lt&semi;一&gt&semi;

    分页     在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...

随机推荐

  1. &lbrack;转&rsqb; 安装DotNetCore&period;1&period;0&period;1-VS2015Tools&period;Preview2&period;0&period;2出现0x80072f8a未指定的错误

    原文地址:安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.2出现0x80072f8a未指定的错误 最近DotNetCore更新到了1.0.1,Azure tools ...

  2. Scrumworks乱码

    要搞敏捷,先找个工具.选了scrumworks5.1.安装完后发现录入汉字乱码. 环境: server:CentOS linux db:mysql5.0 appserver:jboss(scrumwo ...

  3. 【无聊放个模板系列】POJ2752 EXKMP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...

  4. 发一个讨论帖,如果结果被采纳的话可以给一份adb 代码,以及我封装的ADBLIB

    如何在手机没有root 的情况下,获取系统的一些文件,比如 /data/data/xxxx 目录下的文件. 有任何想法的请说出来.

  5. 动态规划之一ones

    n给一个整数n,要你找一个值为n的表达式,这个表达式只有1 + * ( ) 够成.并且1不能连续,比如11+1就不合法. n输入n,(1<=n<=10000) n输出最少需要多少个1才能构 ...

  6. JavaBean--简介及基本使用

    JavaBean本身就是一个类,属于java的面向对象编程 JavaBean是使用java语言开发的一个可重用的组建,在JSP开发中如果要应用JSP提供的JavaBean标签来操作简单的类的话,需要满 ...

  7. Java&lowbar;基础篇(数组排序)

    Java_基础之数组排序(从小到大) 1.冒泡排序: 冒泡排序可以写成两层循环. 每次循环将最大的数值交换到数组的最后一个. 每排序完一次,后面就少比较一次.所以二层循环的判断条件写成:arry.le ...

  8. e578&period; Setting the Clipping Area with a Shape

    This example demonstrates how to set a clipping area using a shape. The example sets an oval for the ...

  9. 三:Mybatis知识整理&lpar;3&rpar;

    一:mybatis中模糊查询的方法: 1.直接传参法:在java传参时进行拼接 -- %keyword% 2.mysql内置函数:concart('%',#{keyword},'%') -- 拼接sq ...

  10. PAT 1035 插入与归并

    https://pintia.cn/problem-sets/994805260223102976/problems/994805286714327040 据*的定义: 插入排序是迭代算法,逐一 ...