《ASP.NET1200例》当前上下文中不存在名称configurationmanager
当前上下文中不存在名称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的更多相关文章
- Visual Studio 当前上下文中不存在名称“ConfigurationManager”
Visual Studio调试出现错误:当前上下文中不存在名称“ConfigurationManager” 解决方法: 1.System.Configuration引用这个dll参考:http://k ...
- C#中提示:当前上下文中不存在名称“ConfigurationManager”
场景 想要在程序中获取App.config中设置的内容. 想要通过 ConfigurationManager.AppSettings[key]; 来进行获取,已经添加 using System.Con ...
- asp.net webform 当前上下文中不存在名称“__o”
错误 CS0103 当前上下文中不存在名称“__o” 最近在搞一个webform项目, 再页面写了点<%%>代码, 结果编译下居然出现了这个错误 炸裂啊, 这是什么毛线, 看起来是 In ...
- 《ASP.NET1200例》实现投票的用户控件
用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...
- 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片
aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...
- 《ASP.NET1200例》ListView控件之修改,删除与添加
aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>
ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...
- 《ASP.NET1200例》解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”
VS2005下,添加了母版页这个控件,我们可以讲N个页面中共同的部分放在母版页来实现,并让WEB窗体集成自我们的母版页,就可以让我们的站点具有统一的风格了.在VS2005SP1之前的版本中,我们只能创 ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>
分页 在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...
随机推荐
- Cas_个人理解
分为三个部分: 1.Cas服务器(用于验证用户是否正确) 1.用户信息存在服务端,其它客户端应用程序修改用户信息后需要同步到服务端 2.用户信息一般存储在服务端的数据 ...
- Jquery-处理iframe的高度自适应
超级简单的方法,也不用写什么判断浏览器高度.宽度啥的.下面的两种方法自选其一就行了.一个是放在和iframe同页面的,一个是放在test.html页面的.注意别放错地方了哦. iframe代码,注意要 ...
- 【UVA 1451】Average
题 题意 求长度为n的01串中1占总长(大于L)的比例最大的一个子串起点和终点. 分析 前缀和s[i]保存前i个数有几个1,[j+1,i] 这段区间1的比例就是(s[i]-s[j])/(i-j),于是 ...
- iOS-编译简单静态库初探
首先声明,我写的这些网上都有更详细的内容,在这里只是写下我自己总结的一些重要内容,具体步骤如下: 事先准备:新建工程-Framework & Library - Cocoa Touch Sta ...
- 43.Android之ListView中BaseAdapter学习
实际开发中个人觉得用的比较多是BaseAdapter,尽管使用起来比其他适配器有些麻烦,但是使用它却能实现很多自己喜欢的列表布局,比如ListView.GridView.Gallery.Spinner ...
- 16.(转) Android之Support v4、v7、v13的区别和应用场景
我们在项目中经常会碰到Android Support v4.v7和v13包兼容问题,所以有必要梳理下这些东西. google提供了Android Support Library package 系列的 ...
- codevs1500 后缀排序
题目描述 Description 天凯是MIT的新生.Prof. HandsomeG给了他一个长度为n的由小写字母构成的字符串,要求他把该字符串的n个后缀(suffix)从小到大排序. 何谓后缀?假设 ...
- TCP/IP详解 笔记九
广播和多播 多播和广播只能用于UDP包,TCP明确在两个进程间建立连接. 多播:帧只传送给属于多播组的多个接口 主机对帧的过滤过程: 通常网卡只接收那些目的地址为本物理接口地址或广播地址的帧:设置为混 ...
- POJ 2752 Seek the Name, Seek the Fame
传送门 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14761 Accepted: 7407 Description ...
- c++中string类型用下标初始化后str.size()为0 输出string值为空
你的string list是个默认构造函数,这样就没有为list分配空间,自然list[i]就会报出超出string范围的错误,可以简单更改为string list(6, '\0'),事先为list指 ...