我一直在努力初始化我的公共静态列表myListPerson。 我想在我的列表中有一个人,每次我运行mvc项目时都是管理员。 我不确定我的代码中出错了什么,请在尝试初始化我的公开列表时帮助指出我的错误。
以下是我的控制器;
you just check your update query:
string SqlString = "UPDATE ProductList SET Pname = ?";
change to this:
string SqlString = "UPDATE ProductList SET Pname =@Pname ";
and change command parameter to pass scaler variable:
cmd.Parameters.AddWithValue("@Pname", prdname.Text);
以下是我的视图显示我的员工名单
public class HomeController : Controller
{
// holds all new people registered in system in this list
public static List<Person> myListPerson = new List<Person>();
Customer myCustomer = new Customer();
Employee myEmployee = new Employee();
//increamental customer number for ViewCustomer
int Cus_Number = 1000;
public ActionResult ViewCustomer(string Name, string Surname, string Email, int Cell, int IDNumber)
{
Cus_Number = Cus_Number + 1;
myCustomer.Name = Name;
myCustomer.Surname = Surname;
myCustomer.Email = Email;
myCustomer.Cell = Cell;
myCustomer.IDNumber = IDNumber;
myCustomer.CustomerID = "Cus" + Cus_Number;
myListPerson.Add(myCustomer);
return View(myListPerson);
}
// GET: Index
public ActionResult Index()
{// I tried set admin values here but it still does not work when i check my view which displays people in list
myEmployee.Name = "1";
myEmployee.Surname = "1";
myEmployee.Email = "1";
myEmployee.Cell = 0;
myEmployee.IDNumber = 0;
myEmployee.EmployeeID = "Emp" + 1000;
myListPerson.Add(myEmployee);
return View(myListPerson);
}