当前上下文中不存在名称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 当前上下文中不存在名称“ConfigurationManager”

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

  2. C#中提示:当前上下文中不存在名称“ConfigurationManager”

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

  3. asp.net webform 当前上下文中不存在名称“__o”

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

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

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

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

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

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

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

  7. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>

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

  8. 《ASP.NET1200例》解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”

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

  9. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>

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

随机推荐

  1. Java设计模式-责任链模式(Chain of Responsibility)

    接下来我们将要谈谈责任链模式,有多个对象,每个对象持有对下一个对象的引用,这样就会形成一条链,请求在这条链上传递,直到某一对象决定处理该请求.但是发出者并不清楚到底最终那个对象会处理该请求,所以,责任 ...

  2. 【BZOJ-1406】密码箱 约数 + 乱搞 + set?

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1143  Solved: 677[Submit][Status][ ...

  3. BZOJ-4300 绝世好(蛋疼)题 DP(递推)

    翻zky学长的blog时翻出来的..... 4300: 绝世好题 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 736 Solved: 393 [Sub ...

  4. 【poj2226】 Muddy Fields

    http://poj.org/problem?id=2226 (题目链接) 题意 给出一个只包含‘.’和‘*’的矩阵,用任意长度的宽为1的木板覆盖所有的‘*’而不覆盖‘.’,木板必须跟矩形的长或宽平行 ...

  5. CruiseControl.NET开篇

    在这里说明一下,我终于踏上了CruiseControl.NET这条不归路了,为什么我会觉得是一条不归路,原因很简单,就是这东西在现在这个阶段已经很久没有在园子里有活跃度了,基本上到了已经可以到了让大家 ...

  6. JSON后端页面解析

    json-lib 请求: http://localhost:8080/MyWeb/pay?cmd=getUrl&param={"OrderId":"sddd111 ...

  7. c++实现gray code(格雷码)

    今天别人问的一道题,强调用分治法实现 =.= 百度了一下格雷码,然后写了一下. 关于格雷码大家看百度的吧,特别详细,贴个图: 代码如下(header_file.h是我自己写的一个头文件,包括常见的ve ...

  8. HD 1011 Starship Troopers(树上的背包)

    Starship Troopers Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. electron加载jquery报错问题

    <!-- Insert this line above script imports --> <script>if (typeof module === 'object') { ...

  10. User表格式

    "_id":基本是700多 "name":"xx01" "pwd":"123"