DBhelper异常求高人解决 在线等
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="connString" connectionString="Data Sourse=.;Initial Catalog=NetBarMIS;uid=xjqaini;pwd=237711"/>
</connectionStrings>
</configuration>
上面数据库链接
namespace NetBarMIS.Cls
{
class DBHelper
{
private static string sConn = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ToString();
private static SqlConnection conn = new SqlConnection(sConn);
/// <summary>
/// 打开数据库连接
/// </summary>
public static void Open()
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
/// <summary>
/// 关闭数据库连接
/// </summary>
public static void Close()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
/// <summary>
/// Scalar方法
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static object ExecuteScalar(string sql)
{
object obj = null;
SqlCommand comm = new SqlCommand(sql, conn);
try
{
Open();
obj = comm.ExecuteScalar();
}
catch
{
throw;
}
finally
{
Close();
}
return obj;
}
/// <summary>
/// NonQuery方法
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static int ExecuteNonQuery(string sql)
{
int iResult;
SqlCommand comm = new SqlCommand(sql, conn);
try
{
Open();
iResult = comm.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
Close();
}
return iResult;
}
/// <summary>
/// Reader方法
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static SqlDataReader ExecuteReader(string sql)
{
SqlDataReader dr;
SqlCommand comm = new SqlCommand(sql, conn);
try
{
Open();
dr = comm.ExecuteReader();
}
catch
{
throw;
}
return dr;
}
/// <