可行,不过你的方法必须是没状态的,
SQLHelper就是。

解决方案 »

  1.   

    静态类应该加static
    public class static DataAccess{
        public static ConnString = "数据库连接字符串";
        public static SelectData(){查询语句};
        public static InsertData(){插入语句};
        public static DeleteData(){删除语句};
        public static UpdateData(){更新语句}; 
    }
      

  2.   

    SqlHelper public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)
    {
    //pass through the call providing null for the set of SqlParameters
    return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null);
    } public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
    {
    //create & open a SqlConnection, and dispose of it after we are done.
    using (SqlConnection cn = new SqlConnection(connectionString))
    {
    cn.Open(); //call the overload that takes a connection in place of the connection string
    return ExecuteNonQuery(cn, commandType, commandText, commandParameters);
    }
    }
    public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues)
    {
    //if we receive parameter values, we need to figure out where they go
    if ((parameterValues != null) && (parameterValues.Length > 0)) 
    {
    //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
    SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); //assign the provided values to these parameters based on parameter order
    AssignParameterValues(commandParameters, parameterValues); //call the overload that takes an array of SqlParameters
    return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters);
    }
    //otherwise we can just call the SP without params
    else 
    {
    return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);
    }
    }