我有两个文件,第一个是VehicleMaster.aspx.cs,另一个是Vehicle.cs类 当我想从我的Vehicle.cs访问函数时它给了我错误,你错过了使用指令或程序集引用?
VehicleMaster.aspx,的.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CarRentalERP.DL;
using CarRentalERP.BL;
namespace CarRentalERP
{
public partial class Vehicle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
Vehicle objvehicle = new Vehicle();
string value = objvehicle.RegVehicle1(txtvehicleno.Text.Trim(), txtvehicletype.Text.Trim(), txtvehiclename.Text.Trim(), txtVehiclemodel.Text.Trim(), Convert.ToInt32(txtyearofpassing.Text.Trim()),
txtinsuranceexpirydate.Text.Trim(),txtvehivleregistrationdate.Text.Trim(),Convert.ToInt32(txtvehicleregistrationno.Text.Trim()),
Convert.ToInt32(txtvehiclepermitno.Text.Trim()),txtvehiclepermitexpirydate.Text.Trim(),txtPUCExpirydate.Text.Trim(),txtengineno.Text.Trim(),
txtColor.Text.Trim(),txtclass.Text.Trim(),txtfueltype.Text.Trim(),txttaxexpirydate.Text.Trim(),Convert.ToInt32(txtseatingcapacity.Text.Trim()));
long id = Convert.ToInt64(value);
if (id > 0)
{
lblmsg.Text = "Register successfully";
}
else
{
lblmsg.Text = "Register Fail";
}
}
}
}
Vehicle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.Validation;
using System.Diagnostics;
using CarRentalERP.DL;
namespace CarRentalERP.BL
{
public class Vehicle
{
CarRantalERPEntities objcon = new CarRantalERPEntities();
public string RegVehicle1(string VehicleNo,string VehicleType, string VehicleName, string VehicleModel,int YearOfPassing, DateTime InsuranceExpiryDate,
DateTime VehicleRegistrationDate,int VehicleRegistrationNo, int VehiclePermitNo, DateTime VehiclePermitExpiryDate,
DateTime PUCExpiryDate, string EngineNo, string Color, string Class, string FuelType, DateTime TaxExpiryDate,int SeatingCapacity)
{
string ID;
try
{
VehicleMaster objVehicle = new VehicleMaster();
objVehicle.VehicleNo = VehicleNo;
objVehicle.VehicleType = VehicleType;
objVehicle.VehicleName = VehicleName;
objVehicle.VehicleModel = VehicleModel;
objVehicle.YearOfPassing = YearOfPassing;
objVehicle.InsuranceExpiryDate = InsuranceExpiryDate;
objVehicle.VehicleRegistrationDate = VehicleRegistrationDate;
objVehicle.VehicleRegistrationNo = VehicleRegistrationNo;
objVehicle.VehiclePermitNo = VehiclePermitNo;
objVehicle.VehiclePermitExpiryDate = VehiclePermitExpiryDate;
objVehicle.PUCExpiryDate = PUCExpiryDate;
objVehicle.EngineNo = EngineNo;
objVehicle.Color = Color;
objVehicle.Class=Class;
objVehicle.FuelType = FuelType;
objVehicle.TaxExpiryDate = TaxExpiryDate;
objVehicle.SeatingCapacity = SeatingCapacity;
objcon.VehicleMasters.Add(objVehicle);
objcon.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
Trace.TraceInformation("Property: {0} Error: {1}",
validationError.PropertyName,
validationError.ErrorMessage);
}
}
}
catch
{
ID = null;
return ID;
}
ID = "1";
return ID;
}
}
}
我在objvehicle.RegVehicle1行
时收到此错误答案 0 :(得分:1)
啊我看到你的Vehicle类(继承自object
的那个)和Vehicle类(继承System.Web.UI.Page
的那个)在不同的命名空间中。他们的完全限定名称是:
CarRentalERP.BL.Vehicle
CarRentalERP.Vehicle
分别。这就是您无法从CarRentalERP.BL.Vehicle
命名空间访问CarRentalERP
的原因。通常你可以添加
using CarRentalERP.BL;
在您的VehicleMaster.aspx,.cs文件中。但是,如果您这样做,则会发生名称冲突。我的建议是你应该将你的CarRentalERP.Vehicle
类重命名为其他类,然后使用using语句。
如果它仍然无法正常工作,那意味着您没有将引用放入。我假设您使用的是Visual Studio。在解决方案资源管理器中,右键单击引用 - >添加参考,然后在对话框中浏览您的项目或类库。
答案 1 :(得分:0)