继续求救 用户代码未处理 System.TypeInitializationException
用户代码未处理 System.TypeInitializationException
Message="“SqlStore”的类型初始值设定项引发异常。"
Source="App_Code.9q0h7pwk"
TypeName="SqlStore"
StackTrace:
在 SqlStore.SqlPage(String tableName, String tableId, String field, String order, String where, Int32 pageCurrent, Int32 pageSize, Int32& recordAmount, Int32& pageAmount)
在 manage_commend.ShowPage(Int32 requestPage) 位置 e:\itx\manage\commend.aspx.cs:行号 103
在 manage_commend.Page_Load(Object sender, EventArgs e) 位置 e:\itx\manage\commend.aspx.cs:行号 28
在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
在 System.Web.UI.Control.OnLoad(EventArgs e)
在 System.Web.UI.Control.LoadRecursive()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.NullReferenceException
Message="
未将对象引用设置到对象的实例。"
Source="App_Code.9q0h7pwk"
StackTrace:
在 SqlStore..cctor() 位置 e:\itx\App_Code\SqlStore.cs:行号 18
InnerException:
SqlStore.cs 第18行 public class SqlStore
{
public static string RootPath = "";//根目录
private static string connection = System.Configuration.ConfigurationManager.ConnectionStrings["sqlserver"].ConnectionString;
SqlStore.SqlPage 的配置:
public static DataTable SqlPage(string tableName, string tableId, string field, string order, string where, int pageCurrent, int pageSize, ref int recordAmount, ref int pageAmount)
{
DataTable table = new DataTable();
SqlConnection SqlConn = new SqlConnection(connection);
SqlConn.Open();
SqlCommand comm = new SqlCommand("novel_page", SqlConn);
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.Parameters.Add("@tbname", SqlDbType.NVarChar, 4000).Value = tableName;
comm.Parameters.Add("@FieldKey", SqlDbType.NVarChar, 4000).Value = tableId;
comm.Parameters.Add("@PageCurrent", SqlDbType.Int).Value = pageCurrent;
comm.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize;
comm.Parameters.Add("@FieldShow", SqlDbType.NVarChar, 1000).Value = field;
comm.Parameters.Add("@FieldOrder", SqlDbType.NVarChar, 1000).Value = order;
comm.Parameters.Add("@Where", SqlDbType.NVarChar, 1000).Value = where;
comm.Parameters.Add("@PageCount", SqlDbType.Int).Direction = ParameterDirection.Output;
comm.Parameters.Add("@RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlDataAdapter data = new SqlDataAdapter(comm);
data.Fill(table);
data.Dispose();
SqlConn.Close();
recordAmount = (int)comm.Parameters["@RecordCount"].Value;
pageAmount = (int)comm.Parameters["@PageCount"].Value;
comm.Dispose();
return table;
}
------解决方案--------------------
数据库字段定义是SqlDbType.NVarChar类型吗。还是varchar?