CodeBehind无法加载类型

时间:2017-04-10 13:40:28

标签: c# asp.net

我的代码存在这个奇怪的问题。当它在我的本地机器上运行时它工作得很好,但是当我在服务器上发布它时,它突然无法检索类型。它似乎不会导出所有文件。我收到的错误 Error Received

我尝试了CodeFile并且它可以正常工作,但我稍后在无法加载ObjectDataSource的地方收到同样的错误。我检查了继承,看起来还不错......

以下是代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TheDatabase.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form2" runat="server">
    <div>

        <asp:DropDownList ID="ddl_VehicleList" runat="server">
            <asp:ListItem>V4</asp:ListItem>
        </asp:DropDownList>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="ods_PnDetails">
            <Columns>
                <asp:BoundField DataField="Vehicle" HeaderText="Vehicle" SortExpression="Vehicle" />
                <asp:BoundField DataField="VCC" HeaderText="VCC" SortExpression="VCC" />
                <asp:BoundField DataField="QuantM1" HeaderText="QuantM1" SortExpression="QuantM1" />
                <asp:BoundField DataField="VehM1" HeaderText="VehM1" SortExpression="VehM1" />
                <asp:BoundField DataField="JCI" HeaderText="JCI" SortExpression="JCI" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
        <asp:ObjectDataSource ID="ods_PnDetails" runat="server" SelectMethod="GetResult" TypeName="TheDatabase.PNDetailsDataAccessLayer">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddl_VehicleList" DefaultValue="V4" Name="VehicleID" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </div>

    </form>
</body>
</html>

它是Default.aspx.cs,它是空的

using System;

namespace TheDatabase
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


    }

}

和我的对象数据源

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;

namespace TheDatabase
{
    public class SQLUlaznaTabela
    {
        public string Vehicle { get; set; }
        public string VCC { get; set; }
        public string QuantM1 { get; set; }
        public string VehM1 { get; set; }
        public string JCI { get; set; }
        public string Description { get; set; }
    }

    public class PNDetailsDataAccessLayer
    {
        public PNDetailsDataAccessLayer()
        {

        }
        public List<SQLUlaznaTabela> GetResult(string VehicleID)
        {
            List<SQLUlaznaTabela> ulaz = new List<SQLUlaznaTabela>();
            string SC = ConfigurationManager.ConnectionStrings["QuotationCalculationDB"].ConnectionString;

            using (SqlConnection con = new SqlConnection(SC))
            {
                SqlCommand cmd = new SqlCommand("Select Vehicle, VCC,QuantM1,VehM1,Description from ProdPerVehicleLastYear where Vehicle = @Vehicle", con);
                SqlParameter param = new SqlParameter("@Vehicle", VehicleID);
                cmd.Parameters.Add(param);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    SQLUlaznaTabela ulazniRed = new SQLUlaznaTabela();
                    ulazniRed.Vehicle = rdr["Vehicle"].ToString();
                    ulazniRed.VCC = rdr["VCC"].ToString();
                    ulazniRed.QuantM1 = rdr["QuantM1"].ToString();
                    ulazniRed.VehM1 = rdr["VehM1"].ToString();
                    ulazniRed.Description = rdr["Description"].ToString();
                    ulaz.Add(ulazniRed);
                }

            }

            return ulaz;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我很困惑,因为我的代码没问题,结果发现我还没有在IIS中启动我的应用程序。对我感到羞耻......